From a0bf1a7f2e27944ef9e3bd3b5940ca511cbc333e Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Mon, 19 Aug 2002 19:33:36 +0000 Subject: Fix pg_dump to dump serial columns as serials. Per pghackers discussion, cause SERIAL column declaration not to imply UNIQUE, so that this can be done without creating an extra index. --- doc/src/sgml/datatype.sgml | 42 ++++++++++++++++++++++++------------------ doc/src/sgml/release.sgml | 3 ++- 2 files changed, 26 insertions(+), 19 deletions(-) (limited to 'doc/src') diff --git a/doc/src/sgml/datatype.sgml b/doc/src/sgml/datatype.sgml index bf53769a1e0..aa4e25ccb60 100644 --- a/doc/src/sgml/datatype.sgml +++ b/doc/src/sgml/datatype.sgml @@ -1,5 +1,5 @@ @@ -665,14 +665,17 @@ CREATE TABLE tablename ( CREATE SEQUENCE tablename_colname_seq; CREATE TABLE tablename ( - colname integer DEFAULT nextval('tablename_colname_seq') UNIQUE NOT NULL + colname integer DEFAULT nextval('tablename_colname_seq') NOT NULL ); Thus, we have created an integer column and arranged for its default - values to be assigned from a sequence generator. UNIQUE and NOT NULL - constraints are applied to ensure that explicitly-inserted values - will never be duplicates, either. + values to be assigned from a sequence generator. A NOT NULL + constraint is applied to ensure that a NULL value cannot be explicitly + inserted, either. In most cases you would also want to attach a + UNIQUE or PRIMARY KEY constraint to prevent + duplicate values from being inserted by accident, but this is + not automatic. @@ -685,20 +688,23 @@ CREATE TABLE tablename ( - Implicit sequences supporting the serial types are - not automatically dropped when a table containing a serial type - is dropped. So, the following commands executed in order will likely fail: - - -CREATE TABLE tablename (colname SERIAL); -DROP TABLE tablename; -CREATE TABLE tablename (colname SERIAL); - - - The sequence will remain in the database until explicitly dropped using - DROP SEQUENCE. (This annoyance will probably be - fixed in some future release.) + The sequence created by a serial type is automatically + dropped when + the owning column is dropped, and cannot be dropped otherwise. + (This was not true in PostgreSQL releases + before 7.3. Note that this automatic drop linkage will not occur for a + sequence created by reloading a dump from a pre-7.3 database; the dump + file does not contain the information needed to establish the dependency + link.) + + + Prior to PostgreSQL 7.3, serial + implied UNIQUE. This is no longer automatic. If + you wish a serial column to be UNIQUE or a + PRIMARY KEY it must now be specified, same as with + any other datatype. + diff --git a/doc/src/sgml/release.sgml b/doc/src/sgml/release.sgml index 9bfc6de17b0..1878fd356ef 100644 --- a/doc/src/sgml/release.sgml +++ b/doc/src/sgml/release.sgml @@ -1,5 +1,5 @@ @@ -24,6 +24,7 @@ CDATA means the content is "SGML-free", so you can write without worries about funny characters. -->