Correct grammar in picksplit debug messages
[PostgreSQL.git] / src / test / regress / sql / temp.sql
blob5183c727f5e70139d71ab345ce548f8d175baf06
1 --
2 -- TEMP
3 -- Test temp relations and indexes
4 --
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;
20 DROP TABLE temptest;
22 SELECT * FROM temptest;
24 DROP INDEX i_temptest;
26 DROP TABLE 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;
40 DROP TABLE temptest;
42 SELECT * FROM temptest;
44 DROP TABLE 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;
58 BEGIN;
59 INSERT INTO temptest VALUES (1);
60 INSERT INTO temptest VALUES (2);
62 SELECT * FROM temptest;
63 COMMIT;
65 SELECT * FROM temptest;
67 DROP TABLE temptest;
69 BEGIN;
70 CREATE TEMP TABLE temptest(col) ON COMMIT DELETE ROWS AS SELECT 1;
72 SELECT * FROM temptest;
73 COMMIT;
75 SELECT * FROM temptest;
77 DROP TABLE temptest;
79 -- Test ON COMMIT DROP
81 BEGIN;
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;
89 COMMIT;
91 SELECT * FROM temptest;
93 BEGIN;
94 CREATE TEMP TABLE temptest(col) ON COMMIT DROP AS SELECT 1;
96 SELECT * FROM temptest;
97 COMMIT;
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;
106 -- Test foreign keys
107 BEGIN;
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);
113 COMMIT;
114 SELECT * FROM temptest1;
115 SELECT * FROM temptest2;
117 BEGIN;
118 CREATE TEMP TABLE temptest3(col int PRIMARY KEY) ON COMMIT DELETE ROWS;
119 CREATE TEMP TABLE temptest4(col int REFERENCES temptest3);
120 COMMIT;
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;
138 select whoami();
140 -- can list temp first explicitly, but it still doesn't affect functions
141 set search_path = pg_temp, public;
142 select * from whereami;
143 select whoami();
145 -- or put it last for security
146 set search_path = public, pg_temp;
147 select * from whereami;
148 select whoami();
150 -- you can invoke a temp function explicitly, though
151 select pg_temp.whoami();
153 drop table public.whereami;