3 -- Test temp relations and indexes
6 -- test temp table/index masking
8 CREATE TABLE temptest(col int);
10 CREATE INDEX i_temptest ON temptest(col);
12 CREATE TEMP TABLE temptest(tcol int);
14 CREATE INDEX i_temptest ON temptest(tcol);
16 SELECT * FROM temptest;
18 DROP INDEX i_temptest;
22 SELECT * FROM temptest;
24 DROP INDEX i_temptest;
28 -- test temp table selects
30 CREATE TABLE temptest(col int);
32 INSERT INTO temptest VALUES (1);
34 CREATE TEMP TABLE temptest(tcol float);
36 INSERT INTO temptest VALUES (2.1);
38 SELECT * FROM temptest;
42 SELECT * FROM temptest;
46 -- test temp table deletion
48 CREATE TEMP TABLE temptest(col int);
52 SELECT * FROM temptest;
54 -- Test ON COMMIT DELETE ROWS
56 CREATE TEMP TABLE temptest(col int) ON COMMIT DELETE ROWS;
59 INSERT INTO temptest VALUES (1);
60 INSERT INTO temptest VALUES (2);
62 SELECT * FROM temptest;
65 SELECT * FROM temptest;
70 CREATE TEMP TABLE temptest(col) ON COMMIT DELETE ROWS AS SELECT 1;
72 SELECT * FROM temptest;
75 SELECT * FROM temptest;
79 -- Test ON COMMIT DROP
83 CREATE TEMP TABLE temptest(col int) ON COMMIT DROP;
85 INSERT INTO temptest VALUES (1);
86 INSERT INTO temptest VALUES (2);
88 SELECT * FROM temptest;
91 SELECT * FROM temptest;
94 CREATE TEMP TABLE temptest(col) ON COMMIT DROP AS SELECT 1;
96 SELECT * FROM temptest;
99 SELECT * FROM temptest;
101 -- ON COMMIT is only allowed for TEMP
103 CREATE TABLE temptest(col int) ON COMMIT DELETE ROWS;
104 CREATE TABLE temptest(col) ON COMMIT DELETE ROWS AS SELECT 1;
108 CREATE TEMP TABLE temptest1(col int PRIMARY KEY);
109 CREATE TEMP TABLE temptest2(col int REFERENCES temptest1)
110 ON COMMIT DELETE ROWS;
111 INSERT INTO temptest1 VALUES (1);
112 INSERT INTO temptest2 VALUES (1);
114 SELECT * FROM temptest1;
115 SELECT * FROM temptest2;
118 CREATE TEMP TABLE temptest3(col int PRIMARY KEY) ON COMMIT DELETE ROWS;
119 CREATE TEMP TABLE temptest4(col int REFERENCES temptest3);
122 -- Test manipulation of temp schema's placement in search path
124 create table public.whereami (f1 text);
125 insert into public.whereami values ('public');
127 create temp table whereami (f1 text);
128 insert into whereami values ('temp');
130 create function public.whoami() returns text
131 as $$select 'public'::text$$ language sql;
133 create function pg_temp.whoami() returns text
134 as $$select 'temp'::text$$ language sql;
136 -- default should have pg_temp implicitly first, but only for tables
137 select * from whereami;
140 -- can list temp first explicitly, but it still doesn't affect functions
141 set search_path = pg_temp, public;
142 select * from whereami;
145 -- or put it last for security
146 set search_path = public, pg_temp;
147 select * from whereami;
150 -- you can invoke a temp function explicitly, though
151 select pg_temp.whoami();
153 drop table public.whereami;