summaryrefslogtreecommitdiff
path: root/src/test/regress/expected/sequence.out
diff options
context:
space:
mode:
authorTom Lane2005-10-02 23:50:16 +0000
committerTom Lane2005-10-02 23:50:16 +0000
commitaa731ed8433914641e42f32fec0fcf27f01aab7e (patch)
tree7120217579cb1a88552c7a1ee44cc0a0749d6e3e /src/test/regress/expected/sequence.out
parent1b61ee3c69ccd869bddc56ae1021797a517ca9b7 (diff)
Change nextval and other sequence functions to specify their sequence
argument as a 'regclass' value instead of a text string. The frontend conversion of text string to pg_class OID is now encapsulated as an implicitly-invocable coercion from text to regclass. This provides backwards compatibility to the old behavior when the sequence argument is explicitly typed as 'text'. When the argument is just an unadorned literal string, it will be taken as 'regclass', which means that the stored representation will be an OID. This solves longstanding problems with renaming sequences that are referenced in default expressions, as well as new-in-8.1 problems with renaming such sequences' schemas or moving them to another schema. All per recent discussion. Along the way, fix some rather serious problems in dbmirror's support for mirroring sequence operations (int4 vs int8 confusion for instance).
Diffstat (limited to 'src/test/regress/expected/sequence.out')
-rw-r--r--src/test/regress/expected/sequence.out111
1 files changed, 107 insertions, 4 deletions
diff --git a/src/test/regress/expected/sequence.out b/src/test/regress/expected/sequence.out
index 6e919d1f1de..ca9ece284b0 100644
--- a/src/test/regress/expected/sequence.out
+++ b/src/test/regress/expected/sequence.out
@@ -19,18 +19,82 @@ SELECT * FROM serialTest;
force | 100
(3 rows)
-
+-- basic sequence operations using both text and oid references
CREATE SEQUENCE sequence_test;
-BEGIN;
-SELECT nextval('sequence_test');
+SELECT nextval('sequence_test'::text);
nextval
---------
1
(1 row)
+SELECT nextval('sequence_test'::regclass);
+ nextval
+---------
+ 2
+(1 row)
+
+SELECT currval('sequence_test'::text);
+ currval
+---------
+ 2
+(1 row)
+
+SELECT currval('sequence_test'::regclass);
+ currval
+---------
+ 2
+(1 row)
+
+SELECT setval('sequence_test'::text, 32);
+ setval
+--------
+ 32
+(1 row)
+
+SELECT nextval('sequence_test'::regclass);
+ nextval
+---------
+ 33
+(1 row)
+
+SELECT setval('sequence_test'::text, 99, false);
+ setval
+--------
+ 99
+(1 row)
+
+SELECT nextval('sequence_test'::regclass);
+ nextval
+---------
+ 99
+(1 row)
+
+SELECT setval('sequence_test'::regclass, 32);
+ setval
+--------
+ 32
+(1 row)
+
+SELECT nextval('sequence_test'::text);
+ nextval
+---------
+ 33
+(1 row)
+
+SELECT setval('sequence_test'::regclass, 99, false);
+ setval
+--------
+ 99
+(1 row)
+
+SELECT nextval('sequence_test'::text);
+ nextval
+---------
+ 99
+(1 row)
+
DROP SEQUENCE sequence_test;
-END;
-- renaming sequences
CREATE SEQUENCE foo_seq;
ALTER TABLE foo_seq RENAME TO foo_seq_new;
@@ -41,6 +105,45 @@ SELECT * FROM foo_seq_new;
(1 row)
DROP SEQUENCE foo_seq_new;
+-- renaming serial sequences
+ALTER TABLE serialtest_f2_seq RENAME TO serialtest_f2_foo;
+INSERT INTO serialTest VALUES ('more');
+SELECT * FROM serialTest;
+ f1 | f2
+-------+-----
+ foo | 1
+ bar | 2
+ force | 100
+ more | 3
+(4 rows)
+
+--
+-- Check dependencies of serial and ordinary sequences
+--
+CREATE TEMP SEQUENCE myseq2;
+CREATE TEMP SEQUENCE myseq3;
+CREATE TEMP TABLE t1 (
+ f1 serial,
+ f2 int DEFAULT nextval('myseq2'),
+ f3 int DEFAULT nextval('myseq3'::text)
+);
+NOTICE: CREATE TABLE will create implicit sequence "t1_f1_seq" for serial column "t1.f1"
+-- Both drops should fail, but with different error messages:
+DROP SEQUENCE t1_f1_seq;
+ERROR: cannot drop sequence t1_f1_seq because table t1 column f1 requires it
+HINT: You may drop table t1 column f1 instead.
+DROP SEQUENCE myseq2;
+NOTICE: default for table t1 column f2 depends on sequence myseq2
+ERROR: cannot drop sequence myseq2 because other objects depend on it
+HINT: Use DROP ... CASCADE to drop the dependent objects too.
+-- This however will work:
+DROP SEQUENCE myseq3;
+DROP TABLE t1;
+-- Fails because no longer existent:
+DROP SEQUENCE t1_f1_seq;
+ERROR: sequence "t1_f1_seq" does not exist
+-- Now OK:
+DROP SEQUENCE myseq2;
--
-- Alter sequence
--