aboutsummaryrefslogtreecommitdiff
path: root/src/test/regress/expected/transactions.out
blob: cc3004dbb28d505371654fec3f78a24785ffbc5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
--
-- TRANSACTIONS
--
BEGIN;
SELECT * 
   INTO TABLE xacttest
   FROM aggtest;
INSERT INTO xacttest (a, b) VALUES (777, 777.777);
END;
-- should retrieve one value--
SELECT a FROM xacttest WHERE a > 100;
  a  
-----
 777
(1 row)

BEGIN;
CREATE TABLE disappear (a int4);
DELETE FROM aggtest;
-- should be empty
SELECT * FROM aggtest;
 a | b 
---+---
(0 rows)

ABORT;
-- should not exist 
SELECT oid FROM pg_class WHERE relname = 'disappear';
 oid 
-----
(0 rows)

-- should have members again 
SELECT * FROM aggtest;
  a  |    b    
-----+---------
  56 |     7.8
 100 |  99.097
   0 | 0.09561
  42 |  324.78
(4 rows)

-- Read-only tests
CREATE TABLE writetest (a int);
CREATE TEMPORARY TABLE temptest (a int);
SET SESSION CHARACTERISTICS AS TRANSACTION READ ONLY;
DROP TABLE writetest; -- fail
ERROR:  transaction is read-only
INSERT INTO writetest VALUES (1); -- fail
ERROR:  transaction is read-only
SELECT * FROM writetest; -- ok
 a 
---
(0 rows)

DELETE FROM temptest; -- ok
UPDATE temptest SET a = 0 WHERE a = 1 AND writetest.a = temptest.a; -- ok
PREPARE test AS UPDATE writetest SET a = 0; -- ok
EXECUTE test; -- fail
ERROR:  transaction is read-only
SELECT * FROM writetest, temptest; -- ok
 a | a 
---+---
(0 rows)

CREATE TABLE test AS SELECT * FROM writetest; -- fail
ERROR:  transaction is read-only
START TRANSACTION READ WRITE;
DROP TABLE writetest; -- ok
COMMIT;
-- Subtransactions, basic tests
-- create & drop tables
SET SESSION CHARACTERISTICS AS TRANSACTION READ WRITE;
CREATE TABLE foobar (a int);
BEGIN;
	CREATE TABLE foo (a int);
	BEGIN;
		DROP TABLE foo;
		CREATE TABLE bar (a int);
	ROLLBACK;
	BEGIN;
		CREATE TABLE baz (a int);
	COMMIT;
	drop TABLE foobar;
	CREATE TABLE barbaz (a int);
COMMIT;
-- should exist: barbaz, baz, foo
SELECT * FROM foo;		-- should be empty
 a 
---
(0 rows)

SELECT * FROM bar;		-- shouldn't exist
ERROR:  relation "bar" does not exist
SELECT * FROM barbaz;	-- should be empty
 a 
---
(0 rows)

SELECT * FROM baz;		-- should be empty
 a 
---
(0 rows)

-- inserts
BEGIN;
	INSERT INTO foo VALUES (1);
	BEGIN;
		INSERT into bar VALUES (1);
ERROR:  relation "bar" does not exist
	ROLLBACK;
	BEGIN;
		INSERT into barbaz VALUES (1);
	COMMIT;
	BEGIN;
		BEGIN;
			INSERT INTO foo VALUES (2);
		COMMIT;
	ROLLBACK;
	INSERT INTO foo VALUES (3);
COMMIT;
SELECT * FROM foo;		-- should have 1 and 3
 a 
---
 1
 3
(2 rows)

SELECT * FROM barbaz;	-- should have 1
 a 
---
 1
(1 row)

-- check that starting a subxact in a failed xact or subxact works
BEGIN;
	SELECT 0/0;		-- fail the outer xact
ERROR:  division by zero
	BEGIN;
		SELECT 1;	-- this should NOT work
ERROR:  current transaction is aborted, commands ignored until end of transaction block
	COMMIT;
	SELECT 1;		-- this should NOT work
ERROR:  current transaction is aborted, commands ignored until end of transaction block
	BEGIN;
		SELECT 1;	-- this should NOT work
ERROR:  current transaction is aborted, commands ignored until end of transaction block
	ROLLBACK;
	SELECT 1;		-- this should NOT work
ERROR:  current transaction is aborted, commands ignored until end of transaction block
COMMIT;
SELECT 1;			-- this should work
 ?column? 
----------
        1
(1 row)

BEGIN;
	BEGIN;
		SELECT 1;	-- this should work
 ?column? 
----------
        1
(1 row)

		SELECT 0/0;	-- fail the subxact
ERROR:  division by zero
		SELECT 1;	-- this should NOT work
ERROR:  current transaction is aborted, commands ignored until end of transaction block
		BEGIN;
			SELECT 1;	-- this should NOT work
ERROR:  current transaction is aborted, commands ignored until end of transaction block
		ROLLBACK;
		BEGIN;
			SELECT 1;	-- this should NOT work
ERROR:  current transaction is aborted, commands ignored until end of transaction block
		COMMIT;
		SELECT 1;	-- this should NOT work
ERROR:  current transaction is aborted, commands ignored until end of transaction block
	ROLLBACK;
	SELECT 1;		-- this should work
 ?column? 
----------
        1
(1 row)

COMMIT;
SELECT 1;			-- this should work
 ?column? 
----------
        1
(1 row)

-- check non-transactional behavior of cursors
BEGIN;
	DECLARE c CURSOR FOR SELECT unique2 FROM tenk1;
	BEGIN;
		FETCH 10 FROM c;
 unique2 
---------
       0
       1
       2
       3
       4
       5
       6
       7
       8
       9
(10 rows)

	ROLLBACK;
	BEGIN;
		FETCH 10 FROM c;
 unique2 
---------
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
(10 rows)

	COMMIT;
	FETCH 10 FROM c;
 unique2 
---------
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
(10 rows)

	CLOSE c;
	DECLARE c CURSOR FOR SELECT unique2/0 FROM tenk1;
	BEGIN;
		FETCH 10 FROM c;
ERROR:  division by zero
	ROLLBACK;
	-- c is now dead to the world ...
	BEGIN;
		FETCH 10 FROM c;
ERROR:  portal "c" cannot be run
	ROLLBACK;
	FETCH 10 FROM c;
ERROR:  portal "c" cannot be run
COMMIT;
DROP TABLE foo;
DROP TABLE baz;
DROP TABLE barbaz;