Auto Increment Key In Postgresql

October 7, 2017

In MySql and MariaDB you can create a unique identity value for rows with the AUTO_INCREMENT attribute. PostgreSQL has the same idea with the SERIAL attribute.

CREATE TABLE domains
(id SERIAL PRIMARY KEY,
 name VARCHAR(254) UNIQUE,
 timestamp TIMESTAMPTZ NOT NULL DEFAULT NOW()
 );
 

The example also shows how to have a column which stores the time when the record was created.



Tags: postgresql