- The serial data types are not truly types, but are a
- notational convenience for setting up unique identifier columns
- in tables.
- In the current implementation, specifying
+ The serial data type is not a true type, but merely
+ a notational convenience for setting up identifier columns
+ (similar to the AUTO_INCREMENT property
+ supported by some other databases). In the current
+ implementation, specifying
CREATE TABLE tablename (
not automatic.
+ To use a serial column to insert the next value of
+ the sequence into the table, specify that the serial
+ column should be assigned the default value. This can be done
+ either be excluding from the column from the list of columns in
+ the INSERT statement, or through the use of
+ the DEFAULT keyword.
+
+
The type names serial and serial4 are
equivalent: both create integer columns. The type
names bigserial and serial8 work just
the same way, except that they create a bigint
column. bigserial should be used if you anticipate
- the use of more than 231> identifiers over the lifetime of the table.
+ the use of more than 231> identifiers over the
+ lifetime of the table.
- 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.)
+ 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.) Furthermore, this dependency between sequence
+ and column is made only for the serial> column itself; if
+ any other columns reference the sequence (perhaps by manually
+ calling the nextval()>) function), they may be broken
+ if the sequence is removed. Using serial> columns in
+ fashion is considered bad form.
- 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 data type.
-
+
+ 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, just as
+ with any other data type.
+
+