8 INSERT INTO xacttest (a, b) VALUES (777, 777.777);
10 -- should retrieve one value--
11 SELECT a FROM xacttest WHERE a > 100;
18 CREATE TABLE disappear (a int4);
21 SELECT * FROM aggtest;
28 SELECT oid FROM pg_class WHERE relname = 'disappear';
33 -- should have members again
34 SELECT * FROM aggtest;
44 CREATE TABLE writetest (a int);
45 CREATE TEMPORARY TABLE temptest (a int);
46 SET SESSION CHARACTERISTICS AS TRANSACTION READ ONLY;
47 DROP TABLE writetest; -- fail
48 ERROR: transaction is read-only
49 INSERT INTO writetest VALUES (1); -- fail
50 ERROR: transaction is read-only
51 SELECT * FROM writetest; -- ok
56 DELETE FROM temptest; -- ok
57 UPDATE temptest SET a = 0 FROM writetest WHERE temptest.a = 1 AND writetest.a = temptest.a; -- ok
58 PREPARE test AS UPDATE writetest SET a = 0; -- ok
60 ERROR: transaction is read-only
61 SELECT * FROM writetest, temptest; -- ok
66 CREATE TABLE test AS SELECT * FROM writetest; -- fail
67 ERROR: transaction is read-only
68 START TRANSACTION READ WRITE;
69 DROP TABLE writetest; -- ok
71 -- Subtransactions, basic tests
72 -- create & drop tables
73 SET SESSION CHARACTERISTICS AS TRANSACTION READ WRITE;
74 CREATE TABLE foobar (a int);
76 CREATE TABLE foo (a int);
79 CREATE TABLE bar (a int);
80 ROLLBACK TO SAVEPOINT one;
81 RELEASE SAVEPOINT one;
83 CREATE TABLE baz (a int);
84 RELEASE SAVEPOINT two;
86 CREATE TABLE barbaz (a int);
88 -- should exist: barbaz, baz, foo
89 SELECT * FROM foo; -- should be empty
94 SELECT * FROM bar; -- shouldn't exist
95 ERROR: relation "bar" does not exist
96 LINE 1: SELECT * FROM bar;
98 SELECT * FROM barbaz; -- should be empty
103 SELECT * FROM baz; -- should be empty
110 INSERT INTO foo VALUES (1);
112 INSERT into bar VALUES (1);
113 ERROR: relation "bar" does not exist
114 LINE 1: INSERT into bar VALUES (1);
117 RELEASE SAVEPOINT one;
119 INSERT into barbaz VALUES (1);
123 INSERT INTO foo VALUES (2);
124 RELEASE SAVEPOINT four;
125 ROLLBACK TO SAVEPOINT three;
126 RELEASE SAVEPOINT three;
127 INSERT INTO foo VALUES (3);
129 SELECT * FROM foo; -- should have 1 and 3
136 SELECT * FROM barbaz; -- should have 1
142 -- test whole-tree commit
146 ERROR: column "foo" does not exist
149 ROLLBACK TO SAVEPOINT one;
150 RELEASE SAVEPOINT one;
152 CREATE TABLE savepoints (a int);
154 INSERT INTO savepoints VALUES (1);
156 INSERT INTO savepoints VALUES (2);
158 INSERT INTO savepoints VALUES (3);
159 ROLLBACK TO SAVEPOINT five;
161 COMMIT; -- should not be in a transaction block
162 WARNING: there is no transaction in progress
163 SELECT * FROM savepoints;
170 -- test whole-tree rollback
173 DELETE FROM savepoints WHERE a=1;
174 RELEASE SAVEPOINT one;
176 DELETE FROM savepoints WHERE a=1;
178 DELETE FROM savepoints WHERE a=2;
180 COMMIT; -- should not be in a transaction block
181 WARNING: there is no transaction in progress
183 SELECT * FROM savepoints;
190 -- test whole-tree commit on an aborted subtransaction
192 INSERT INTO savepoints VALUES (4);
194 INSERT INTO savepoints VALUES (5);
196 ERROR: column "foo" does not exist
200 SELECT * FROM savepoints;
208 INSERT INTO savepoints VALUES (6);
210 INSERT INTO savepoints VALUES (7);
211 RELEASE SAVEPOINT one;
212 INSERT INTO savepoints VALUES (8);
214 -- rows 6 and 8 should have been created by the same xact
215 SELECT a.xmin = b.xmin FROM savepoints a, savepoints b WHERE a.a=6 AND b.a=8;
221 -- rows 6 and 7 should have been created by different xacts
222 SELECT a.xmin = b.xmin FROM savepoints a, savepoints b WHERE a.a=6 AND b.a=7;
229 INSERT INTO savepoints VALUES (9);
231 INSERT INTO savepoints VALUES (10);
232 ROLLBACK TO SAVEPOINT one;
233 INSERT INTO savepoints VALUES (11);
235 SELECT a FROM savepoints WHERE a in (9, 10, 11);
242 -- rows 9 and 11 should have been created by different xacts
243 SELECT a.xmin = b.xmin FROM savepoints a, savepoints b WHERE a.a=9 AND b.a=11;
250 INSERT INTO savepoints VALUES (12);
252 INSERT INTO savepoints VALUES (13);
254 INSERT INTO savepoints VALUES (14);
255 ROLLBACK TO SAVEPOINT one;
256 INSERT INTO savepoints VALUES (15);
258 INSERT INTO savepoints VALUES (16);
260 INSERT INTO savepoints VALUES (17);
262 SELECT a FROM savepoints WHERE a BETWEEN 12 AND 17;
272 INSERT INTO savepoints VALUES (18);
274 INSERT INTO savepoints VALUES (19);
276 INSERT INTO savepoints VALUES (20);
277 ROLLBACK TO SAVEPOINT one;
278 INSERT INTO savepoints VALUES (21);
279 ROLLBACK TO SAVEPOINT one;
280 INSERT INTO savepoints VALUES (22);
282 SELECT a FROM savepoints WHERE a BETWEEN 18 AND 22;
289 DROP TABLE savepoints;
290 -- only in a transaction block:
292 ERROR: SAVEPOINT can only be used in transaction blocks
293 ROLLBACK TO SAVEPOINT one;
294 ERROR: ROLLBACK TO SAVEPOINT can only be used in transaction blocks
295 RELEASE SAVEPOINT one;
296 ERROR: RELEASE SAVEPOINT can only be used in transaction blocks
297 -- Only "rollback to" allowed in aborted state
301 ERROR: division by zero
302 SAVEPOINT two; -- ignored till the end of ...
303 ERROR: current transaction is aborted, commands ignored until end of transaction block
304 RELEASE SAVEPOINT one; -- ignored till the end of ...
305 ERROR: current transaction is aborted, commands ignored until end of transaction block
306 ROLLBACK TO SAVEPOINT one;
314 SELECT 1; -- this should work
320 -- check non-transactional behavior of cursors
322 DECLARE c CURSOR FOR SELECT unique2 FROM tenk1 ORDER BY unique2;
339 ROLLBACK TO SAVEPOINT one;
355 RELEASE SAVEPOINT one;
372 DECLARE c CURSOR FOR SELECT unique2/0 FROM tenk1 ORDER BY unique2;
375 ERROR: division by zero
376 ROLLBACK TO SAVEPOINT two;
377 -- c is now dead to the world ...
379 ERROR: portal "c" cannot be run
380 ROLLBACK TO SAVEPOINT two;
381 RELEASE SAVEPOINT two;
383 ERROR: portal "c" cannot be run
386 -- Check that "stable" functions are really stable. They should not be
387 -- able to see the partial results of the calling query. (Ideally we would
388 -- also check that they don't see commits of concurrent transactions, but
389 -- that's a mite hard to do within the limitations of pg_regress.)
391 select * from xacttest;
401 create or replace function max_xacttest() returns smallint language sql as
402 'select max(a) from xacttest' stable;
404 update xacttest set a = max_xacttest() + 10 where a > 0;
405 select * from xacttest;
416 -- But a volatile function can see the partial results of the calling query
417 create or replace function max_xacttest() returns smallint language sql as
418 'select max(a) from xacttest' volatile;
420 update xacttest set a = max_xacttest() + 10 where a > 0;
421 select * from xacttest;
432 -- Now the same test with plpgsql (since it depends on SPI which is different)
433 create or replace function max_xacttest() returns smallint language plpgsql as
434 'begin return max(a) from xacttest; end' stable;
436 update xacttest set a = max_xacttest() + 10 where a > 0;
437 select * from xacttest;
448 create or replace function max_xacttest() returns smallint language plpgsql as
449 'begin return max(a) from xacttest; end' volatile;
451 update xacttest set a = max_xacttest() + 10 where a > 0;
452 select * from xacttest;
463 -- test case for problems with dropping an open relation during abort
466 CREATE TABLE koju (a INT UNIQUE);
467 NOTICE: CREATE TABLE / UNIQUE will create implicit index "koju_a_key" for table "koju"
468 INSERT INTO koju VALUES (1);
469 INSERT INTO koju VALUES (1);
470 ERROR: duplicate key value violates unique constraint "koju_a_key"
472 CREATE TABLE koju (a INT UNIQUE);
473 NOTICE: CREATE TABLE / UNIQUE will create implicit index "koju_a_key" for table "koju"
474 INSERT INTO koju VALUES (1);
475 INSERT INTO koju VALUES (1);
476 ERROR: duplicate key value violates unique constraint "koju_a_key"
481 -- verify that cursors created during an aborted subtransaction are
482 -- closed, but that we do not rollback the effect of any FETCHs
483 -- performed in the aborted subtransaction
486 create table abc (a int);
487 insert into abc values (5);
488 insert into abc values (10);
489 declare foo cursor for select * from abc;
499 ERROR: cursor "foo" does not exist
502 create table abc (a int);
503 insert into abc values (5);
504 insert into abc values (10);
505 insert into abc values (15);
506 declare foo cursor for select * from abc;
528 -- tests for the "tid" type
529 SELECT '(3, 3)'::tid = '(3, 4)'::tid;
535 SELECT '(3, 3)'::tid = '(3, 3)'::tid;
541 SELECT '(3, 3)'::tid <> '(3, 3)'::tid;
547 SELECT '(3, 3)'::tid <> '(3, 4)'::tid;