...

/

Sequences and the Serial Pseudo Data Type

Sequences and the Serial Pseudo Data Type

Learn how to use sequence in PostgreSQL.

We'll cover the following...

Other kinds of numeric data types in PostgreSQL are smallserial, serial, and bigserial. They’re actually pseudotypes—the parser recognizes their syntax but then transforms them into something else entirely:

CREATE TABLE tablename (
colname SERIAL
);

This is equivalent to specifying:

CREATE SEQUENCE tablename_colname_seq;
CREATE TABLE tablename (
colname integer NOT NULL DEFAULT nextval('tablename_colname_seq')
);
ALTER SEQUENCE tablename_colname_seq OWNED BY tablename.colname;

Sequence

We can use any of these two codes. The sequence SQL object is covered by the SQL standard and documented in the ...