@@ -63,140 +63,185 @@ ERROR: unsupported ON COMMIT and foreign key combination
63
63
DETAIL: Table "temptest4" references "temptest3", but they do not have the same ON COMMIT setting.
64
64
-- For partitioned temp tables, ON COMMIT actions ignore storage-less
65
65
-- partitioned tables.
66
- begin ;
66
+ BEGIN ;
67
67
CREATE GLOBAL TEMP TABLE temp_parted_oncommit (a int)
68
- partition by list (a) on commit delete rows ;
68
+ PARTITION BY LIST (a) ON COMMIT DELETE ROWS ;
69
69
CREATE GLOBAL TEMP TABLE temp_parted_oncommit_1
70
- partition of temp_parted_oncommit
71
- for values in (1) on commit delete rows ;
72
- insert into temp_parted_oncommit values (1);
73
- commit ;
70
+ PARTITION OF temp_parted_oncommit
71
+ FOR VALUES IN (1) ON COMMIT DELETE ROWS ;
72
+ INSERT INTO temp_parted_oncommit VALUES (1);
73
+ COMMIT ;
74
74
-- partitions are emptied by the previous commit
75
- select * from temp_parted_oncommit;
75
+ SELECT * FROM temp_parted_oncommit;
76
76
a
77
77
---
78
78
(0 rows)
79
79
80
- drop table temp_parted_oncommit;
80
+ DROP TABLE temp_parted_oncommit;
81
81
-- Using ON COMMIT DELETE on a partitioned table does not remove
82
82
-- all rows if partitions preserve their data.
83
- begin ;
83
+ BEGIN ;
84
84
CREATE GLOBAL TEMP TABLE temp_parted_oncommit_test (a int)
85
- partition by list (a) on commit delete rows ;
85
+ PARTITION BY LIST (a) ON COMMIT DELETE ROWS ;
86
86
CREATE GLOBAL TEMP TABLE temp_parted_oncommit_test1
87
- partition of temp_parted_oncommit_test
88
- for values in (1) on commit preserve rows ;
89
- insert into temp_parted_oncommit_test values (1);
90
- commit ;
87
+ PARTITION OF temp_parted_oncommit_test
88
+ FOR VALUES IN (1) ON COMMIT PRESERVE ROWS ;
89
+ INSERT INTO temp_parted_oncommit_test VALUES (1);
90
+ COMMIT ;
91
91
-- Data from the remaining partition is still here as its rows are
92
92
-- preserved.
93
- select * from temp_parted_oncommit_test;
93
+ SELECT * FROM temp_parted_oncommit_test;
94
94
a
95
95
---
96
96
1
97
97
(1 row)
98
98
99
99
-- two relations remain in this case.
100
- select relname from pg_class where relname like 'temp_parted_oncommit_test%';
100
+ SELECT relname FROM pg_class WHERE relname LIKE 'temp_parted_oncommit_test%';
101
101
relname
102
102
----------------------------
103
103
temp_parted_oncommit_test
104
104
temp_parted_oncommit_test1
105
105
(2 rows)
106
106
107
- drop table temp_parted_oncommit_test;
107
+ DROP TABLE temp_parted_oncommit_test;
108
108
-- Check dependencies between ON COMMIT actions with inheritance trees.
109
109
-- Data on the parent is removed, and the child goes away.
110
- begin ;
111
- CREATE GLOBAL TEMP TABLE temp_inh_oncommit_test (a int) on commit delete rows ;
110
+ BEGIN ;
111
+ CREATE GLOBAL TEMP TABLE temp_inh_oncommit_test (a int) ON COMMIT DELETE ROWS ;
112
112
CREATE GLOBAL TEMP TABLE temp_inh_oncommit_test1 ()
113
- inherits (temp_inh_oncommit_test) on commit preserve rows ;
114
- insert into temp_inh_oncommit_test1 values (1);
115
- insert into temp_inh_oncommit_test values (1);
116
- commit ;
117
- select * from temp_inh_oncommit_test;
113
+ INHERITS (temp_inh_oncommit_test) ON COMMIT PRESERVE ROWS ;
114
+ INSERT INTO temp_inh_oncommit_test1 VALUES (1);
115
+ INSERT INTO temp_inh_oncommit_test VALUES (1);
116
+ COMMIT ;
117
+ SELECT * FROM temp_inh_oncommit_test;
118
118
a
119
119
---
120
120
1
121
121
(1 row)
122
122
123
123
-- two relations remain
124
- select relname from pg_class where relname like 'temp_inh_oncommit_test%';
125
- relname
124
+ SELECT relname FROM pg_class WHERE relname LIKE 'temp_inh_oncommit_test%';
125
+ relname
126
126
-------------------------
127
127
temp_inh_oncommit_test
128
128
temp_inh_oncommit_test1
129
129
(2 rows)
130
130
131
- drop table temp_inh_oncommit_test;
132
- -- Tests with two-phase commit
133
- -- Transactions creating objects in a temporary namespace cannot be used
134
- -- with two-phase commit.
135
- -- These cases generate errors about temporary namespace.
136
- -- Function creation
137
- begin;
138
- create function pg_temp.twophase_func() returns void as
139
- $$ select '2pc_func'::text $$ language sql;
140
- prepare transaction 'twophase_func';
141
- ERROR: cannot PREPARE a transaction that has operated on temporary objects
142
- -- Function drop
143
- create function pg_temp.twophase_func() returns void as
144
- $$ select '2pc_func'::text $$ language sql;
145
- begin;
146
- drop function pg_temp.twophase_func();
147
- prepare transaction 'twophase_func';
148
- ERROR: cannot PREPARE a transaction that has operated on temporary objects
149
- -- Operator creation
150
- begin;
151
- create operator pg_temp.@@ (leftarg = int4, rightarg = int4, procedure = int4mi);
152
- prepare transaction 'twophase_operator';
153
- ERROR: cannot PREPARE a transaction that has operated on temporary objects
154
- -- These generate errors about temporary tables.
155
- begin;
156
- create type pg_temp.twophase_type as (a int);
157
- prepare transaction 'twophase_type';
158
- ERROR: cannot PREPARE a transaction that has operated on temporary objects
159
- begin;
160
- create view pg_temp.twophase_view as select 1;
161
- prepare transaction 'twophase_view';
162
- ERROR: cannot PREPARE a transaction that has operated on temporary objects
163
- begin;
164
- create sequence pg_temp.twophase_seq;
165
- prepare transaction 'twophase_sequence';
166
- ERROR: cannot PREPARE a transaction that has operated on temporary objects
167
- -- Temporary tables cannot be used with two-phase commit.
168
- CREATE GLOBAL TEMP TABLE twophase_tab (a int);
169
- begin;
170
- select a from twophase_tab;
131
+ DROP TABLE temp_inh_oncommit_test1;
132
+ DROP TABLE temp_inh_oncommit_test;
133
+ -- Global temp table cannot inherit from temporary relation
134
+ BEGIN;
135
+ CREATE TEMP TABLE global_temp_table (a int) ON COMMIT DELETE ROWS;
136
+ CREATE GLOBAL TEMP TABLE global_temp_table1 ()
137
+ INHERITS(global_temp_table) ON COMMIT PRESERVE ROWS;
138
+ ERROR: cannot inherit from temporary relation "global_temp_table"
139
+ ROLLBACK;
140
+ -- Temp table can inherit from global temporary relation
141
+ BEGIN;
142
+ CREATE GLOBAL TEMP TABLE global_temp_table (a int) ON COMMIT DELETE ROWS;
143
+ CREATE TEMP TABLE temp_table1 ()
144
+ INHERITS(global_temp_table) ON COMMIT PRESERVE ROWS;
145
+ CREATE TEMP TABLE temp_table2 ()
146
+ INHERITS(global_temp_table) ON COMMIT DELETE ROWS;
147
+ INSERT INTO temp_table2 VALUES (2);
148
+ INSERT INTO temp_table1 VALUES (1);
149
+ INSERT INTO global_temp_table VALUES (0);
150
+ SELECT * FROM global_temp_table;
171
151
a
172
152
---
173
- (0 rows)
153
+ 0
154
+ 1
155
+ 2
156
+ (3 rows)
157
+
158
+ COMMIT;
159
+ SELECT * FROM global_temp_table;
160
+ a
161
+ ---
162
+ 1
163
+ (1 row)
174
164
175
- prepare transaction 'twophase_tab';
176
- ERROR: cannot PREPARE a transaction that has operated on temporary objects
177
- begin;
178
- insert into twophase_tab values (1);
179
- prepare transaction 'twophase_tab';
180
- ERROR: cannot PREPARE a transaction that has operated on temporary objects
181
- begin;
182
- lock twophase_tab in access exclusive mode;
183
- prepare transaction 'twophase_tab';
184
- ERROR: cannot PREPARE a transaction that has operated on temporary objects
185
- begin;
186
- drop table twophase_tab;
187
- prepare transaction 'twophase_tab';
188
- ERROR: cannot PREPARE a transaction that has operated on temporary objects
189
- -- Corner case: current_schema may create a temporary schema if namespace
190
- -- creation is pending, so check after that. First reset the connection
191
- -- to remove the temporary namespace.
192
- \c -
193
- SET search_path TO 'pg_temp';
165
+ DROP TABLE temp_table2;
166
+ DROP TABLE temp_table1;
167
+ DROP TABLE global_temp_table;
168
+ -- Global temp table can inherit from normal relation
194
169
BEGIN;
195
- SELECT current_schema() ~ 'pg_temp' AS is_temp_schema;
196
- is_temp_schema
197
- ----------------
198
- t
170
+ CREATE TABLE normal_table (a int);
171
+ CREATE GLOBAL TEMP TABLE temp_table1 ()
172
+ INHERITS(normal_table) ON COMMIT PRESERVE ROWS;
173
+ CREATE GLOBAL TEMP TABLE temp_table2 ()
174
+ INHERITS(normal_table) ON COMMIT DELETE ROWS;
175
+ INSERT INTO temp_table2 VALUES (2);
176
+ INSERT INTO temp_table1 VALUES (1);
177
+ INSERT INTO normal_table VALUES (0);
178
+ SELECT * FROM normal_table;
179
+ a
180
+ ---
181
+ 0
182
+ 1
183
+ 2
184
+ (3 rows)
185
+
186
+ COMMIT;
187
+ SELECT * FROM normal_table;
188
+ a
189
+ ---
190
+ 0
191
+ 1
192
+ (2 rows)
193
+
194
+ DROP TABLE temp_table2;
195
+ DROP TABLE temp_table1;
196
+ DROP TABLE normal_table;
197
+ -- Check SERIAL and BIGSERIAL pseudo-types
198
+ CREATE GLOBAL TEMP TABLE global_temp_table ( aid BIGSERIAL, bid SERIAL );
199
+ CREATE SEQUENCE test_sequence;
200
+ INSERT INTO global_temp_table DEFAULT VALUES;
201
+ INSERT INTO global_temp_table DEFAULT VALUES;
202
+ INSERT INTO global_temp_table DEFAULT VALUES;
203
+ SELECT * FROM global_temp_table;
204
+ aid | bid
205
+ -----+-----
206
+ 1 | 1
207
+ 2 | 2
208
+ 3 | 3
209
+ (3 rows)
210
+
211
+ SELECT NEXTVAL( 'test_sequence' );
212
+ nextval
213
+ ---------
214
+ 1
215
+ (1 row)
216
+
217
+ \c
218
+ SELECT * FROM global_temp_table;
219
+ aid | bid
220
+ -----+-----
221
+ (0 rows)
222
+
223
+ SELECT NEXTVAL( 'test_sequence' );
224
+ nextval
225
+ ---------
226
+ 2
227
+ (1 row)
228
+
229
+ INSERT INTO global_temp_table DEFAULT VALUES;
230
+ INSERT INTO global_temp_table DEFAULT VALUES;
231
+ INSERT INTO global_temp_table DEFAULT VALUES;
232
+ SELECT * FROM global_temp_table;
233
+ aid | bid
234
+ -----+-----
235
+ 1 | 1
236
+ 2 | 2
237
+ 3 | 3
238
+ (3 rows)
239
+
240
+ SELECT NEXTVAL( 'test_sequence' );
241
+ nextval
242
+ ---------
243
+ 3
199
244
(1 row)
200
245
201
- PREPARE TRANSACTION 'twophase_search' ;
202
- ERROR: cannot PREPARE a transaction that has operated on temporary objects
246
+ DROP TABLE global_temp_table ;
247
+ DROP SEQUENCE test_sequence;
0 commit comments