~vcs-imports/mammoth-replicator/trunk

« back to all changes in this revision

Viewing changes to src/test/regress/expected/transactions.out

  • Committer: alvherre
  • Date: 2005-12-16 21:24:52 UTC
  • Revision ID: svn-v4:db760fc0-0f08-0410-9d63-cc6633f64896:trunk:1
Initial import of the REL8_0_3 sources from the Pgsql CVS repository.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
--
 
2
-- TRANSACTIONS
 
3
--
 
4
BEGIN;
 
5
SELECT * 
 
6
   INTO TABLE xacttest
 
7
   FROM aggtest;
 
8
INSERT INTO xacttest (a, b) VALUES (777, 777.777);
 
9
END;
 
10
-- should retrieve one value--
 
11
SELECT a FROM xacttest WHERE a > 100;
 
12
  a  
 
13
-----
 
14
 777
 
15
(1 row)
 
16
 
 
17
BEGIN;
 
18
CREATE TABLE disappear (a int4);
 
19
DELETE FROM aggtest;
 
20
-- should be empty
 
21
SELECT * FROM aggtest;
 
22
 a | b 
 
23
---+---
 
24
(0 rows)
 
25
 
 
26
ABORT;
 
27
-- should not exist 
 
28
SELECT oid FROM pg_class WHERE relname = 'disappear';
 
29
 oid 
 
30
-----
 
31
(0 rows)
 
32
 
 
33
-- should have members again 
 
34
SELECT * FROM aggtest;
 
35
  a  |    b    
 
36
-----+---------
 
37
  56 |     7.8
 
38
 100 |  99.097
 
39
   0 | 0.09561
 
40
  42 |  324.78
 
41
(4 rows)
 
42
 
 
43
-- Read-only tests
 
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
 
52
 a 
 
53
---
 
54
(0 rows)
 
55
 
 
56
DELETE FROM temptest; -- ok
 
57
UPDATE temptest SET a = 0 WHERE a = 1 AND writetest.a = temptest.a; -- ok
 
58
PREPARE test AS UPDATE writetest SET a = 0; -- ok
 
59
EXECUTE test; -- fail
 
60
ERROR:  transaction is read-only
 
61
SELECT * FROM writetest, temptest; -- ok
 
62
 a | a 
 
63
---+---
 
64
(0 rows)
 
65
 
 
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
 
70
COMMIT;
 
71
-- Subtransactions, basic tests
 
72
-- create & drop tables
 
73
SET SESSION CHARACTERISTICS AS TRANSACTION READ WRITE;
 
74
CREATE TABLE foobar (a int);
 
75
BEGIN;
 
76
        CREATE TABLE foo (a int);
 
77
        SAVEPOINT one;
 
78
                DROP TABLE foo;
 
79
                CREATE TABLE bar (a int);
 
80
        ROLLBACK TO SAVEPOINT one;
 
81
        RELEASE SAVEPOINT one;
 
82
        SAVEPOINT two;
 
83
                CREATE TABLE baz (a int);
 
84
        RELEASE SAVEPOINT two;
 
85
        drop TABLE foobar;
 
86
        CREATE TABLE barbaz (a int);
 
87
COMMIT;
 
88
-- should exist: barbaz, baz, foo
 
89
SELECT * FROM foo;              -- should be empty
 
90
 a 
 
91
---
 
92
(0 rows)
 
93
 
 
94
SELECT * FROM bar;              -- shouldn't exist
 
95
ERROR:  relation "bar" does not exist
 
96
SELECT * FROM barbaz;   -- should be empty
 
97
 a 
 
98
---
 
99
(0 rows)
 
100
 
 
101
SELECT * FROM baz;              -- should be empty
 
102
 a 
 
103
---
 
104
(0 rows)
 
105
 
 
106
-- inserts
 
107
BEGIN;
 
108
        INSERT INTO foo VALUES (1);
 
109
        SAVEPOINT one;
 
110
                INSERT into bar VALUES (1);
 
111
ERROR:  relation "bar" does not exist
 
112
        ROLLBACK TO one;
 
113
        RELEASE SAVEPOINT one;
 
114
        SAVEPOINT two;
 
115
                INSERT into barbaz VALUES (1);
 
116
        RELEASE two;
 
117
        SAVEPOINT three;
 
118
                SAVEPOINT four;
 
119
                        INSERT INTO foo VALUES (2);
 
120
                RELEASE SAVEPOINT four;
 
121
        ROLLBACK TO SAVEPOINT three;
 
122
        RELEASE SAVEPOINT three;
 
123
        INSERT INTO foo VALUES (3);
 
124
COMMIT;
 
125
SELECT * FROM foo;              -- should have 1 and 3
 
126
 a 
 
127
---
 
128
 1
 
129
 3
 
130
(2 rows)
 
131
 
 
132
SELECT * FROM barbaz;   -- should have 1
 
133
 a 
 
134
---
 
135
 1
 
136
(1 row)
 
137
 
 
138
-- test whole-tree commit
 
139
BEGIN;
 
140
        SAVEPOINT one;
 
141
                SELECT foo;
 
142
ERROR:  column "foo" does not exist
 
143
        ROLLBACK TO SAVEPOINT one;
 
144
        RELEASE SAVEPOINT one;
 
145
        SAVEPOINT two;
 
146
                CREATE TABLE savepoints (a int);
 
147
                SAVEPOINT three;
 
148
                        INSERT INTO savepoints VALUES (1);
 
149
                        SAVEPOINT four;
 
150
                                INSERT INTO savepoints VALUES (2);
 
151
                                SAVEPOINT five;
 
152
                                        INSERT INTO savepoints VALUES (3);
 
153
                                ROLLBACK TO SAVEPOINT five;
 
154
COMMIT;
 
155
COMMIT;         -- should not be in a transaction block
 
156
WARNING:  there is no transaction in progress
 
157
SELECT * FROM savepoints;
 
158
 a 
 
159
---
 
160
 1
 
161
 2
 
162
(2 rows)
 
163
 
 
164
-- test whole-tree rollback
 
165
BEGIN;
 
166
        SAVEPOINT one;
 
167
                DELETE FROM savepoints WHERE a=1;
 
168
        RELEASE SAVEPOINT one;
 
169
        SAVEPOINT two;
 
170
                DELETE FROM savepoints WHERE a=1;
 
171
                SAVEPOINT three;
 
172
                        DELETE FROM savepoints WHERE a=2;
 
173
ROLLBACK;
 
174
COMMIT;         -- should not be in a transaction block
 
175
WARNING:  there is no transaction in progress
 
176
                
 
177
SELECT * FROM savepoints;
 
178
 a 
 
179
---
 
180
 1
 
181
 2
 
182
(2 rows)
 
183
 
 
184
-- test whole-tree commit on an aborted subtransaction
 
185
BEGIN;
 
186
        INSERT INTO savepoints VALUES (4);
 
187
        SAVEPOINT one;
 
188
                INSERT INTO savepoints VALUES (5);
 
189
                SELECT foo;
 
190
ERROR:  column "foo" does not exist
 
191
COMMIT;
 
192
SELECT * FROM savepoints;
 
193
 a 
 
194
---
 
195
 1
 
196
 2
 
197
(2 rows)
 
198
 
 
199
BEGIN;
 
200
        INSERT INTO savepoints VALUES (6);
 
201
        SAVEPOINT one;
 
202
                INSERT INTO savepoints VALUES (7);
 
203
        RELEASE SAVEPOINT one;
 
204
        INSERT INTO savepoints VALUES (8);
 
205
COMMIT;
 
206
-- rows 6 and 8 should have been created by the same xact
 
207
SELECT a.xmin = b.xmin FROM savepoints a, savepoints b WHERE a.a=6 AND b.a=8;
 
208
 ?column? 
 
209
----------
 
210
 t
 
211
(1 row)
 
212
 
 
213
-- rows 6 and 7 should have been created by different xacts
 
214
SELECT a.xmin = b.xmin FROM savepoints a, savepoints b WHERE a.a=6 AND b.a=7;
 
215
 ?column? 
 
216
----------
 
217
 f
 
218
(1 row)
 
219
 
 
220
BEGIN;
 
221
        INSERT INTO savepoints VALUES (9);
 
222
        SAVEPOINT one;
 
223
                INSERT INTO savepoints VALUES (10);
 
224
        ROLLBACK TO SAVEPOINT one;
 
225
                INSERT INTO savepoints VALUES (11);
 
226
COMMIT;
 
227
SELECT a FROM savepoints WHERE a in (9, 10, 11);
 
228
 a  
 
229
----
 
230
  9
 
231
 11
 
232
(2 rows)
 
233
 
 
234
-- rows 9 and 11 should have been created by different xacts
 
235
SELECT a.xmin = b.xmin FROM savepoints a, savepoints b WHERE a.a=9 AND b.a=11;
 
236
 ?column? 
 
237
----------
 
238
 f
 
239
(1 row)
 
240
 
 
241
BEGIN;
 
242
        INSERT INTO savepoints VALUES (12);
 
243
        SAVEPOINT one;
 
244
                INSERT INTO savepoints VALUES (13);
 
245
                SAVEPOINT two;
 
246
                        INSERT INTO savepoints VALUES (14);
 
247
        ROLLBACK TO SAVEPOINT one;
 
248
                INSERT INTO savepoints VALUES (15);
 
249
                SAVEPOINT two;
 
250
                        INSERT INTO savepoints VALUES (16);
 
251
                        SAVEPOINT three;
 
252
                                INSERT INTO savepoints VALUES (17);
 
253
COMMIT;
 
254
SELECT a FROM savepoints WHERE a BETWEEN 12 AND 17;
 
255
 a  
 
256
----
 
257
 12
 
258
 15
 
259
 16
 
260
 17
 
261
(4 rows)
 
262
 
 
263
BEGIN;
 
264
        INSERT INTO savepoints VALUES (18);
 
265
        SAVEPOINT one;
 
266
                INSERT INTO savepoints VALUES (19);
 
267
                SAVEPOINT two;
 
268
                        INSERT INTO savepoints VALUES (20);
 
269
        ROLLBACK TO SAVEPOINT one;
 
270
                INSERT INTO savepoints VALUES (21);
 
271
        ROLLBACK TO SAVEPOINT one;
 
272
                INSERT INTO savepoints VALUES (22);
 
273
COMMIT;
 
274
SELECT a FROM savepoints WHERE a BETWEEN 18 AND 22;
 
275
 a  
 
276
----
 
277
 18
 
278
 22
 
279
(2 rows)
 
280
 
 
281
DROP TABLE savepoints;
 
282
-- only in a transaction block:
 
283
SAVEPOINT one;
 
284
ERROR:  SAVEPOINT may only be used in transaction blocks
 
285
ROLLBACK TO SAVEPOINT one;
 
286
ERROR:  ROLLBACK TO SAVEPOINT may only be used in transaction blocks
 
287
RELEASE SAVEPOINT one;
 
288
ERROR:  RELEASE SAVEPOINT may only be used in transaction blocks
 
289
-- Only "rollback to" allowed in aborted state
 
290
BEGIN;
 
291
  SAVEPOINT one;
 
292
  SELECT 0/0;
 
293
ERROR:  division by zero
 
294
  SAVEPOINT two;    -- ignored till the end of ...
 
295
ERROR:  current transaction is aborted, commands ignored until end of transaction block
 
296
  RELEASE SAVEPOINT one;      -- ignored till the end of ...
 
297
ERROR:  current transaction is aborted, commands ignored until end of transaction block
 
298
  ROLLBACK TO SAVEPOINT one;
 
299
  SELECT 1;
 
300
 ?column? 
 
301
----------
 
302
        1
 
303
(1 row)
 
304
 
 
305
COMMIT;
 
306
SELECT 1;                       -- this should work
 
307
 ?column? 
 
308
----------
 
309
        1
 
310
(1 row)
 
311
 
 
312
-- check non-transactional behavior of cursors
 
313
BEGIN;
 
314
        DECLARE c CURSOR FOR SELECT unique2 FROM tenk1;
 
315
        SAVEPOINT one;
 
316
                FETCH 10 FROM c;
 
317
 unique2 
 
318
---------
 
319
       0
 
320
       1
 
321
       2
 
322
       3
 
323
       4
 
324
       5
 
325
       6
 
326
       7
 
327
       8
 
328
       9
 
329
(10 rows)
 
330
 
 
331
        ROLLBACK TO SAVEPOINT one;
 
332
                FETCH 10 FROM c;
 
333
 unique2 
 
334
---------
 
335
      10
 
336
      11
 
337
      12
 
338
      13
 
339
      14
 
340
      15
 
341
      16
 
342
      17
 
343
      18
 
344
      19
 
345
(10 rows)
 
346
 
 
347
        RELEASE SAVEPOINT one;
 
348
        FETCH 10 FROM c;
 
349
 unique2 
 
350
---------
 
351
      20
 
352
      21
 
353
      22
 
354
      23
 
355
      24
 
356
      25
 
357
      26
 
358
      27
 
359
      28
 
360
      29
 
361
(10 rows)
 
362
 
 
363
        CLOSE c;
 
364
        DECLARE c CURSOR FOR SELECT unique2/0 FROM tenk1;
 
365
        SAVEPOINT two;
 
366
                FETCH 10 FROM c;
 
367
ERROR:  division by zero
 
368
        ROLLBACK TO SAVEPOINT two;
 
369
        -- c is now dead to the world ...
 
370
                FETCH 10 FROM c;
 
371
ERROR:  portal "c" cannot be run
 
372
        ROLLBACK TO SAVEPOINT two;
 
373
        RELEASE SAVEPOINT two;
 
374
        FETCH 10 FROM c;
 
375
ERROR:  portal "c" cannot be run
 
376
COMMIT;
 
377
--
 
378
-- Check that "stable" functions are really stable.  They should not be
 
379
-- able to see the partial results of the calling query.  (Ideally we would
 
380
-- also check that they don't see commits of concurrent transactions, but
 
381
-- that's a mite hard to do within the limitations of pg_regress.)
 
382
--
 
383
select * from xacttest;
 
384
  a  |    b    
 
385
-----+---------
 
386
  56 |     7.8
 
387
 100 |  99.097
 
388
   0 | 0.09561
 
389
  42 |  324.78
 
390
 777 | 777.777
 
391
(5 rows)
 
392
 
 
393
create or replace function max_xacttest() returns smallint language sql as
 
394
'select max(a) from xacttest' stable;
 
395
begin;
 
396
update xacttest set a = max_xacttest() + 10 where a > 0;
 
397
select * from xacttest;
 
398
  a  |    b    
 
399
-----+---------
 
400
   0 | 0.09561
 
401
 787 |     7.8
 
402
 787 |  99.097
 
403
 787 |  324.78
 
404
 787 | 777.777
 
405
(5 rows)
 
406
 
 
407
rollback;
 
408
-- But a volatile function can see the partial results of the calling query
 
409
create or replace function max_xacttest() returns smallint language sql as
 
410
'select max(a) from xacttest' volatile;
 
411
begin;
 
412
update xacttest set a = max_xacttest() + 10 where a > 0;
 
413
select * from xacttest;
 
414
  a  |    b    
 
415
-----+---------
 
416
   0 | 0.09561
 
417
 787 |     7.8
 
418
 797 |  99.097
 
419
 807 |  324.78
 
420
 817 | 777.777
 
421
(5 rows)
 
422
 
 
423
rollback;
 
424
-- Now the same test with plpgsql (since it depends on SPI which is different)
 
425
create or replace function max_xacttest() returns smallint language plpgsql as
 
426
'begin return max(a) from xacttest; end' stable;
 
427
begin;
 
428
update xacttest set a = max_xacttest() + 10 where a > 0;
 
429
select * from xacttest;
 
430
  a  |    b    
 
431
-----+---------
 
432
   0 | 0.09561
 
433
 787 |     7.8
 
434
 787 |  99.097
 
435
 787 |  324.78
 
436
 787 | 777.777
 
437
(5 rows)
 
438
 
 
439
rollback;
 
440
create or replace function max_xacttest() returns smallint language plpgsql as
 
441
'begin return max(a) from xacttest; end' volatile;
 
442
begin;
 
443
update xacttest set a = max_xacttest() + 10 where a > 0;
 
444
select * from xacttest;
 
445
  a  |    b    
 
446
-----+---------
 
447
   0 | 0.09561
 
448
 787 |     7.8
 
449
 797 |  99.097
 
450
 807 |  324.78
 
451
 817 | 777.777
 
452
(5 rows)
 
453
 
 
454
rollback;
 
455
-- test case for problems with dropping an open relation during abort
 
456
BEGIN;
 
457
        savepoint x;
 
458
                CREATE TABLE koju (a INT UNIQUE);
 
459
NOTICE:  CREATE TABLE / UNIQUE will create implicit index "koju_a_key" for table "koju"
 
460
                INSERT INTO koju VALUES (1);
 
461
                INSERT INTO koju VALUES (1);
 
462
ERROR:  duplicate key violates unique constraint "koju_a_key"
 
463
        rollback to x;
 
464
        CREATE TABLE koju (a INT UNIQUE);
 
465
NOTICE:  CREATE TABLE / UNIQUE will create implicit index "koju_a_key" for table "koju"
 
466
        INSERT INTO koju VALUES (1);
 
467
        INSERT INTO koju VALUES (1);
 
468
ERROR:  duplicate key violates unique constraint "koju_a_key"
 
469
ROLLBACK;
 
470
DROP TABLE foo;
 
471
DROP TABLE baz;
 
472
DROP TABLE barbaz;