Creating tables with PostgreSQL

Identity columns

There are three auto incremented identity columns types in PostgreSQL

NameStorageRange
SMALLSERIAL2 bytes1 to 32,767
SERIAL4 bytes1 to 2,147,483,647
BIGSERIAL8 bytes1 to 9,223,372,036,854,775,807

To create a new identity column use the following syntax

CREATE TABLE vehicle(
   id SERIAL PRIMARY KEY,
   name VARCHAR NOT NULL
);

Leave a comment

Your email address will not be published. Required fields are marked *