· 9 years ago · Dec 22, 2016, 12:12 AM
1-- id, location_id, status, year, quarter
2CREATE TABLE foo AS
3SELECT * FROM ( VALUES
4(1, 12, 1, 2014, 3),
5(2, 12, 1, 2014, 4),
6(3, 13, 0, 2015, 1),
7(4, 13, 0, 2015, 2),
8(5, 13, 1, 2015, 3),
9(6, 13, 0, 2015, 4),
10(7, 12, 1, 2015, 1),
11(8, 12, 1, 2015, 2)
12) AS t(id,location_id,status,year,quarter);
13
14select get_info(2015,1,0,0,1)
15
16CREATE or REPLACE FUNCTION get_info(
17get_year int,
18q1 int,
19q2 int,
20q3 int,
21q4 int)
22RETURNS VOID
23AS $$
24DECLARE
25BEGIN
26 CREATE TABLE IF NOT EXISTS tbl_temp
27 ( parcelnum text,
28 quart1 int,
29 quart2 int,
30 quart3 int,
31 quart4 int);
32[ I have prolem with this part:
33INSERT INTO tbl_calc_temp( parcelnum text,quart1 int,
34quart2 int,quart3 int, quart4 int )
35Valuse (select some_thing from foo where quarter = 1 or 4)
36]
37END; $$
38LANGUAGE PLPGSQL;