Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbb3f839

Browse files
committed
Add a variant expected-output file for the sequence regression test, to cover
output that is seen when a checkpoint occurs at just the right time duringthe test. Per my report of 2008-08-31.This could be back-patched but I'm not sure it's worth the trouble.
1 parentb153c09 commitbb3f839

File tree

1 file changed

+290
-0
lines changed

1 file changed

+290
-0
lines changed
Lines changed: 290 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,290 @@
1+
---
2+
--- test creation of SERIAL column
3+
---
4+
5+
CREATE TABLE serialTest (f1 text, f2 serial);
6+
NOTICE: CREATE TABLE will create implicit sequence "serialtest_f2_seq" for serial column "serialtest.f2"
7+
8+
INSERT INTO serialTest VALUES ('foo');
9+
INSERT INTO serialTest VALUES ('bar');
10+
INSERT INTO serialTest VALUES ('force', 100);
11+
INSERT INTO serialTest VALUES ('wrong', NULL);
12+
ERROR: null value in column "f2" violates not-null constraint
13+
14+
SELECT * FROM serialTest;
15+
f1 | f2
16+
-------+-----
17+
foo | 1
18+
bar | 2
19+
force | 100
20+
(3 rows)
21+
22+
-- basic sequence operations using both text and oid references
23+
CREATE SEQUENCE sequence_test;
24+
25+
SELECT nextval('sequence_test'::text);
26+
nextval
27+
---------
28+
1
29+
(1 row)
30+
31+
SELECT nextval('sequence_test'::regclass);
32+
nextval
33+
---------
34+
2
35+
(1 row)
36+
37+
SELECT currval('sequence_test'::text);
38+
currval
39+
---------
40+
2
41+
(1 row)
42+
43+
SELECT currval('sequence_test'::regclass);
44+
currval
45+
---------
46+
2
47+
(1 row)
48+
49+
SELECT setval('sequence_test'::text, 32);
50+
setval
51+
--------
52+
32
53+
(1 row)
54+
55+
SELECT nextval('sequence_test'::regclass);
56+
nextval
57+
---------
58+
33
59+
(1 row)
60+
61+
SELECT setval('sequence_test'::text, 99, false);
62+
setval
63+
--------
64+
99
65+
(1 row)
66+
67+
SELECT nextval('sequence_test'::regclass);
68+
nextval
69+
---------
70+
99
71+
(1 row)
72+
73+
SELECT setval('sequence_test'::regclass, 32);
74+
setval
75+
--------
76+
32
77+
(1 row)
78+
79+
SELECT nextval('sequence_test'::text);
80+
nextval
81+
---------
82+
33
83+
(1 row)
84+
85+
SELECT setval('sequence_test'::regclass, 99, false);
86+
setval
87+
--------
88+
99
89+
(1 row)
90+
91+
SELECT nextval('sequence_test'::text);
92+
nextval
93+
---------
94+
99
95+
(1 row)
96+
97+
DROP SEQUENCE sequence_test;
98+
-- renaming sequences
99+
CREATE SEQUENCE foo_seq;
100+
ALTER TABLE foo_seq RENAME TO foo_seq_new;
101+
SELECT * FROM foo_seq_new;
102+
sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called
103+
---------------+------------+-------------+--------------+---------------------+-----------+-------------+---------+-----------+-----------
104+
foo_seq | 1 | 1 | 1 | 9223372036854775807 | 1 | 1 | 1 | f | f
105+
(1 row)
106+
107+
SELECT nextval('foo_seq_new');
108+
nextval
109+
---------
110+
1
111+
(1 row)
112+
113+
SELECT nextval('foo_seq_new');
114+
nextval
115+
---------
116+
2
117+
(1 row)
118+
119+
SELECT * FROM foo_seq_new;
120+
sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called
121+
---------------+------------+-------------+--------------+---------------------+-----------+-------------+---------+-----------+-----------
122+
foo_seq | 2 | 1 | 1 | 9223372036854775807 | 1 | 1 | 31 | f | t
123+
(1 row)
124+
125+
DROP SEQUENCE foo_seq_new;
126+
-- renaming serial sequences
127+
ALTER TABLE serialtest_f2_seq RENAME TO serialtest_f2_foo;
128+
INSERT INTO serialTest VALUES ('more');
129+
SELECT * FROM serialTest;
130+
f1 | f2
131+
-------+-----
132+
foo | 1
133+
bar | 2
134+
force | 100
135+
more | 3
136+
(4 rows)
137+
138+
--
139+
-- Check dependencies of serial and ordinary sequences
140+
--
141+
CREATE TEMP SEQUENCE myseq2;
142+
CREATE TEMP SEQUENCE myseq3;
143+
CREATE TEMP TABLE t1 (
144+
f1 serial,
145+
f2 int DEFAULT nextval('myseq2'),
146+
f3 int DEFAULT nextval('myseq3'::text)
147+
);
148+
NOTICE: CREATE TABLE will create implicit sequence "t1_f1_seq" for serial column "t1.f1"
149+
-- Both drops should fail, but with different error messages:
150+
DROP SEQUENCE t1_f1_seq;
151+
ERROR: cannot drop sequence t1_f1_seq because other objects depend on it
152+
DETAIL: default for table t1 column f1 depends on sequence t1_f1_seq
153+
HINT: Use DROP ... CASCADE to drop the dependent objects too.
154+
DROP SEQUENCE myseq2;
155+
ERROR: cannot drop sequence myseq2 because other objects depend on it
156+
DETAIL: default for table t1 column f2 depends on sequence myseq2
157+
HINT: Use DROP ... CASCADE to drop the dependent objects too.
158+
-- This however will work:
159+
DROP SEQUENCE myseq3;
160+
DROP TABLE t1;
161+
-- Fails because no longer existent:
162+
DROP SEQUENCE t1_f1_seq;
163+
ERROR: sequence "t1_f1_seq" does not exist
164+
-- Now OK:
165+
DROP SEQUENCE myseq2;
166+
--
167+
-- Alter sequence
168+
--
169+
CREATE SEQUENCE sequence_test2 START WITH 32;
170+
SELECT nextval('sequence_test2');
171+
nextval
172+
---------
173+
32
174+
(1 row)
175+
176+
ALTER SEQUENCE sequence_test2 RESTART WITH 24
177+
INCREMENT BY 4 MAXVALUE 36 MINVALUE 5 CYCLE;
178+
SELECT nextval('sequence_test2');
179+
nextval
180+
---------
181+
24
182+
(1 row)
183+
184+
SELECT nextval('sequence_test2');
185+
nextval
186+
---------
187+
28
188+
(1 row)
189+
190+
SELECT nextval('sequence_test2');
191+
nextval
192+
---------
193+
32
194+
(1 row)
195+
196+
SELECT nextval('sequence_test2');
197+
nextval
198+
---------
199+
36
200+
(1 row)
201+
202+
SELECT nextval('sequence_test2');
203+
nextval
204+
---------
205+
5
206+
(1 row)
207+
208+
ALTER SEQUENCE sequence_test2 RESTART;
209+
SELECT nextval('sequence_test2');
210+
nextval
211+
---------
212+
32
213+
(1 row)
214+
215+
SELECT nextval('sequence_test2');
216+
nextval
217+
---------
218+
36
219+
(1 row)
220+
221+
SELECT nextval('sequence_test2');
222+
nextval
223+
---------
224+
5
225+
(1 row)
226+
227+
-- Test comments
228+
COMMENT ON SEQUENCE asdf IS 'won''t work';
229+
ERROR: relation "asdf" does not exist
230+
COMMENT ON SEQUENCE sequence_test2 IS 'will work';
231+
COMMENT ON SEQUENCE sequence_test2 IS NULL;
232+
-- Test lastval()
233+
CREATE SEQUENCE seq;
234+
SELECT nextval('seq');
235+
nextval
236+
---------
237+
1
238+
(1 row)
239+
240+
SELECT lastval();
241+
lastval
242+
---------
243+
1
244+
(1 row)
245+
246+
SELECT setval('seq', 99);
247+
setval
248+
--------
249+
99
250+
(1 row)
251+
252+
SELECT lastval();
253+
lastval
254+
---------
255+
99
256+
(1 row)
257+
258+
CREATE SEQUENCE seq2;
259+
SELECT nextval('seq2');
260+
nextval
261+
---------
262+
1
263+
(1 row)
264+
265+
SELECT lastval();
266+
lastval
267+
---------
268+
1
269+
(1 row)
270+
271+
DROP SEQUENCE seq2;
272+
-- should fail
273+
SELECT lastval();
274+
ERROR: lastval is not yet defined in this session
275+
CREATE USER seq_user;
276+
BEGIN;
277+
SET LOCAL SESSION AUTHORIZATION seq_user;
278+
CREATE SEQUENCE seq3;
279+
SELECT nextval('seq3');
280+
nextval
281+
---------
282+
1
283+
(1 row)
284+
285+
REVOKE ALL ON seq3 FROM seq_user;
286+
SELECT lastval();
287+
ERROR: permission denied for sequence seq3
288+
ROLLBACK;
289+
DROP USER seq_user;
290+
DROP SEQUENCE seq;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp