~ubuntu-branches/ubuntu/natty/postgresql-8.4/natty-updates

« back to all changes in this revision

Viewing changes to src/test/regress/sql/temp.sql

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2009-03-20 12:00:13 UTC
  • Revision ID: james.westby@ubuntu.com-20090320120013-hogj7egc5mjncc5g
Tags: upstream-8.4~0cvs20090328
ImportĀ upstreamĀ versionĀ 8.4~0cvs20090328

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
--
 
2
-- TEMP
 
3
-- Test temp relations and indexes
 
4
--
 
5
 
 
6
-- test temp table/index masking
 
7
 
 
8
CREATE TABLE temptest(col int);
 
9
 
 
10
CREATE INDEX i_temptest ON temptest(col);
 
11
 
 
12
CREATE TEMP TABLE temptest(tcol int);
 
13
 
 
14
CREATE INDEX i_temptest ON temptest(tcol);
 
15
 
 
16
SELECT * FROM temptest;
 
17
 
 
18
DROP INDEX i_temptest;
 
19
 
 
20
DROP TABLE temptest;
 
21
 
 
22
SELECT * FROM temptest;
 
23
 
 
24
DROP INDEX i_temptest;
 
25
 
 
26
DROP TABLE temptest;
 
27
 
 
28
-- test temp table selects
 
29
 
 
30
CREATE TABLE temptest(col int);
 
31
 
 
32
INSERT INTO temptest VALUES (1);
 
33
 
 
34
CREATE TEMP TABLE temptest(tcol float);
 
35
 
 
36
INSERT INTO temptest VALUES (2.1);
 
37
 
 
38
SELECT * FROM temptest;
 
39
 
 
40
DROP TABLE temptest;
 
41
 
 
42
SELECT * FROM temptest;
 
43
 
 
44
DROP TABLE temptest;
 
45
 
 
46
-- test temp table deletion
 
47
 
 
48
CREATE TEMP TABLE temptest(col int);
 
49
 
 
50
\c
 
51
 
 
52
SELECT * FROM temptest;
 
53
 
 
54
-- Test ON COMMIT DELETE ROWS
 
55
 
 
56
CREATE TEMP TABLE temptest(col int) ON COMMIT DELETE ROWS;
 
57
 
 
58
BEGIN;
 
59
INSERT INTO temptest VALUES (1);
 
60
INSERT INTO temptest VALUES (2);
 
61
 
 
62
SELECT * FROM temptest;
 
63
COMMIT;
 
64
 
 
65
SELECT * FROM temptest;
 
66
 
 
67
DROP TABLE temptest;
 
68
 
 
69
BEGIN;
 
70
CREATE TEMP TABLE temptest(col) ON COMMIT DELETE ROWS AS SELECT 1;
 
71
 
 
72
SELECT * FROM temptest;
 
73
COMMIT;
 
74
 
 
75
SELECT * FROM temptest;
 
76
 
 
77
DROP TABLE temptest;
 
78
 
 
79
-- Test ON COMMIT DROP
 
80
 
 
81
BEGIN;
 
82
 
 
83
CREATE TEMP TABLE temptest(col int) ON COMMIT DROP;
 
84
 
 
85
INSERT INTO temptest VALUES (1);
 
86
INSERT INTO temptest VALUES (2);
 
87
 
 
88
SELECT * FROM temptest;
 
89
COMMIT;
 
90
 
 
91
SELECT * FROM temptest;
 
92
 
 
93
BEGIN;
 
94
CREATE TEMP TABLE temptest(col) ON COMMIT DROP AS SELECT 1;
 
95
 
 
96
SELECT * FROM temptest;
 
97
COMMIT;
 
98
 
 
99
SELECT * FROM temptest;
 
100
 
 
101
-- ON COMMIT is only allowed for TEMP
 
102
 
 
103
CREATE TABLE temptest(col int) ON COMMIT DELETE ROWS;
 
104
CREATE TABLE temptest(col) ON COMMIT DELETE ROWS AS SELECT 1;
 
105
 
 
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;
 
116
 
 
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;
 
121
 
 
122
-- Test manipulation of temp schema's placement in search path
 
123
 
 
124
create table public.whereami (f1 text);
 
125
insert into public.whereami values ('public');
 
126
 
 
127
create temp table whereami (f1 text);
 
128
insert into whereami values ('temp');
 
129
 
 
130
create function public.whoami() returns text
 
131
  as $$select 'public'::text$$ language sql;
 
132
 
 
133
create function pg_temp.whoami() returns text
 
134
  as $$select 'temp'::text$$ language sql;
 
135
 
 
136
-- default should have pg_temp implicitly first, but only for tables
 
137
select * from whereami;
 
138
select whoami();
 
139
 
 
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();
 
144
 
 
145
-- or put it last for security
 
146
set search_path = public, pg_temp;
 
147
select * from whereami;
 
148
select whoami();
 
149
 
 
150
-- you can invoke a temp function explicitly, though
 
151
select pg_temp.whoami();
 
152
 
 
153
drop table public.whereami;