· 7 years ago · Dec 08, 2018, 03:16 AM
1CREATE OR REPLACE FUNCTION test1(user_id BIGINT) RETURNS BIGINT AS
2$BODY$
3
4BEGIN
5 create temp table temp_table1
6 ON COMMIT DELETE ROWS
7
8 as SELECT table1.column1, table1.column2
9 FROM table1
10 INNER JOIN -- ............
11
12 if exists (select * from temp_table1) then
13 -- work with the result
14 return 777;
15 else
16 return 0;
17 end if;
18
19END;
20$BODY$
21LANGUAGE plpgsql;
22
23ERROR: relation "temp_table1" already exists
24
25BEGIN
26 DROP TABLE IF EXISTS temp_table1;
27 create temp table temp_table1
28 -- Your rest Code comes here
29
30begin
31 create temp table temp_table1
32 on commit drop
33...
34
35CREATE TEMP TABLE IF NOT EXISTS MyTempTable AS
36SELECT * FROM MyTable WHERE date_prod >= '2002-01-01';