~ubuntu-branches/ubuntu/oneiric/postgresql-9.1/oneiric-security

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2011-05-11 10:41:53 UTC
  • Revision ID: james.westby@ubuntu.com-20110511104153-psbh2o58553fv1m0
Tags: upstream-9.1~beta1
ImportĀ upstreamĀ versionĀ 9.1~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 |      31 | 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
-- Information schema
 
224
SELECT * FROM information_schema.sequences WHERE sequence_name IN ('sequence_test2');
 
225
 sequence_catalog | sequence_schema | sequence_name  | data_type | numeric_precision | numeric_precision_radix | numeric_scale | start_value | minimum_value | maximum_value | increment | cycle_option 
 
226
------------------+-----------------+----------------+-----------+-------------------+-------------------------+---------------+-------------+---------------+---------------+-----------+--------------
 
227
 regression       | public          | sequence_test2 | bigint    |                64 |                       2 |             0 | 32          | 5             | 36            | 4         | YES
 
228
(1 row)
 
229
 
 
230
-- Test comments
 
231
COMMENT ON SEQUENCE asdf IS 'won''t work';
 
232
ERROR:  relation "asdf" does not exist
 
233
COMMENT ON SEQUENCE sequence_test2 IS 'will work';
 
234
COMMENT ON SEQUENCE sequence_test2 IS NULL;
 
235
-- Test lastval()
 
236
CREATE SEQUENCE seq;
 
237
SELECT nextval('seq');
 
238
 nextval 
 
239
---------
 
240
       1
 
241
(1 row)
 
242
 
 
243
SELECT lastval();
 
244
 lastval 
 
245
---------
 
246
       1
 
247
(1 row)
 
248
 
 
249
SELECT setval('seq', 99);
 
250
 setval 
 
251
--------
 
252
     99
 
253
(1 row)
 
254
 
 
255
SELECT lastval();
 
256
 lastval 
 
257
---------
 
258
      99
 
259
(1 row)
 
260
 
 
261
CREATE SEQUENCE seq2;
 
262
SELECT nextval('seq2');
 
263
 nextval 
 
264
---------
 
265
       1
 
266
(1 row)
 
267
 
 
268
SELECT lastval();
 
269
 lastval 
 
270
---------
 
271
       1
 
272
(1 row)
 
273
 
 
274
DROP SEQUENCE seq2;
 
275
-- should fail
 
276
SELECT lastval();
 
277
ERROR:  lastval is not yet defined in this session
 
278
CREATE USER seq_user;
 
279
BEGIN;
 
280
SET LOCAL SESSION AUTHORIZATION seq_user;
 
281
CREATE SEQUENCE seq3;
 
282
SELECT nextval('seq3');
 
283
 nextval 
 
284
---------
 
285
       1
 
286
(1 row)
 
287
 
 
288
REVOKE ALL ON seq3 FROM seq_user;
 
289
SELECT lastval();
 
290
ERROR:  permission denied for sequence seq3
 
291
ROLLBACK;
 
292
DROP USER seq_user;
 
293
DROP SEQUENCE seq;