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:
Press + to interact
CREATE TABLE tablename (colname SERIAL);
This is equivalent to specifying:
Press + to interact
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;