Serial Data Types

You can declare columns of SERIAL, BIGSERIAL, or SERIAL8 data types. If user-defined routines require whole-number values for variables, arguments, or returned data types, specify INT, BIGINT, or INT8 as the data types, rather than SERIAL, BIGSERIAL, or SERIAL8. These data types are integer data types that differ primarily in their names, their range, and their storage requirements. Columns of serial data types cannot store values less than 1. A table can have no more than one SERIAL column and no more than one BIGSERIAL or SERIAL8 column. Because the serial values are assigned by the database server, you cannot use the UPDATE statement to change an existing serial value in the database.

To insert an explicit value into a SERIAL, BIGSERIAL, or SERIAL8 column, specify any integer greater than zero. For details of an alternative way to generate integer values, see CREATE SEQUENCE statement.

A SERIAL, BIGSERIAL, or SERIAL8 column is unique only if you set a unique index on the column. (The index can also be in the form of a primary key or a unique constraint.) With a unique index, values in serial data type columns are guaranteed to be unique, but successive values are not necessarily contiguous.