From d4f4b971a4eb7992add4e70752aa9d0936c43dcc Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Thu, 16 Aug 2001 20:38:56 +0000 Subject: Sequences are now based on int8, not int4, arithmetic. SERIAL pseudo-type has an alias SERIAL4 and a sister SERIAL8. SERIAL8 is just the same except the created column is type int8 not int4. initdb forced. Note this also breaks any chance of pg_upgrade from 7.1, unless we hack up pg_upgrade to drop and recreate sequences. (Which is not out of the question, but I don't wanna do it.) --- doc/src/sgml/datatype.sgml | 62 ++++++++++++++++++++++++++++------- doc/src/sgml/ref/create_sequence.sgml | 6 ++-- 2 files changed, 53 insertions(+), 15 deletions(-) (limited to 'doc/src') diff --git a/doc/src/sgml/datatype.sgml b/doc/src/sgml/datatype.sgml index 21fa569a016..7f16688f324 100644 --- a/doc/src/sgml/datatype.sgml +++ b/doc/src/sgml/datatype.sgml @@ -1,5 +1,5 @@ @@ -199,10 +199,16 @@ $Header: /cvsroot/pgsql/doc/src/sgml/datatype.sgml,v 1.57 2001/08/07 22:41:49 pe serial - + serial4 autoincrementing four-byte integer + + serial8 + + autoincrementing eight-byte integer + + text @@ -394,10 +400,17 @@ $Header: /cvsroot/pgsql/doc/src/sgml/datatype.sgml,v 1.57 2001/08/07 22:41:49 pe - serial + serial4 4 bytes Identifier or cross-reference - 0 to +2147483647 + 1 to 2147483647 + + + + serial8 + 8 bytes + Identifier or cross-reference + 1 to 9223372036854775807 @@ -413,17 +426,27 @@ $Header: /cvsroot/pgsql/doc/src/sgml/datatype.sgml,v 1.57 2001/08/07 22:41:49 pe - The bigint type may not be available on all platforms since - it relies on compiler support for eight-byte integers. + The bigint type may not function correctly on all platforms, + since it relies on compiler support for eight-byte integers. On a machine + without such support, bigint acts the same + as integer (but still takes up eight bytes of storage). - The Serial Type + The Serial Types serial + + serial4 + + + + serial8 + + auto-increment serial @@ -435,9 +458,9 @@ $Header: /cvsroot/pgsql/doc/src/sgml/datatype.sgml,v 1.57 2001/08/07 22:41:49 pe - The serial type is a special-case type constructed by - Postgres from other existing components. - It is typically used to create unique identifiers for table entries. + The serial datatypes are not truly types, but are a + notational convenience for setting up unique identifier columns + in tables. In the current implementation, specifying @@ -449,10 +472,14 @@ CREATE TABLE tablename ( CREATE SEQUENCE tablename_colname_seq; CREATE TABLE tablename - (colname integer DEFAULT nextval('tablename_colname_seq'); -CREATE UNIQUE INDEX tablename_colname_key on tablename (colname); + (colname integer DEFAULT nextval('tablename_colname_seq') UNIQUE 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. + The implicit sequence created for the serial type will @@ -460,7 +487,18 @@ CREATE UNIQUE INDEX tablename_ + + + The type names serial and serial4 are + equivalent: both create integer columns. The type + name serial8 works just the same way, except that it + creates a bigint column. serial8 should + be used if you anticipate use of more than 2^31 identifiers over + the lifetime of the table. + + + Implicit sequences supporting the serial are not automatically dropped when a table containing a serial type is dropped. So, the following commands executed in order will likely fail: diff --git a/doc/src/sgml/ref/create_sequence.sgml b/doc/src/sgml/ref/create_sequence.sgml index 5d5a59d28ab..4f7b8b296d7 100644 --- a/doc/src/sgml/ref/create_sequence.sgml +++ b/doc/src/sgml/ref/create_sequence.sgml @@ -1,5 +1,5 @@ @@ -79,7 +79,7 @@ CREATE [ TEMPORARY | TEMP ] SEQUENCE seqnameMINVALUE minvalue determines the minimum value - a sequence can generate. The defaults are 1 and -2147483647 for + a sequence can generate. The defaults are 1 and -2^63-1 for ascending and descending sequences, respectively. @@ -92,7 +92,7 @@ CREATE [ TEMPORARY | TEMP ] SEQUENCE seqnameMAXVALUE maxvalue determines the maximum - value for the sequence. The defaults are 2147483647 and -1 for + value for the sequence. The defaults are 2^63-1 and -1 for ascending and descending sequences, respectively. -- cgit v1.2.3