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