Use sequence value as a primary key
postgres=#
postgres=# CREATE SEQUENCE myseq MINVALUE 0;
postgres=# -- Create auto-incrementing DEFAULT and PRIMARY KEY constraint, is:
postgres=#
postgres=# CREATE TABLE shipments
postgres-# (id integer DEFAULT nextval('"myseq"'::text) PRIMARY KEY,
postgres(# customer_id integer,
postgres(# isbn text,
postgres(# ship_date timestamp);
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "shipments_pkey" for table "shipments"
CREATE TABLE
postgres=#
postgres=# drop sequence myseq;
DROP SEQUENCE
postgres=# drop table shipments;
DROP TABLE
postgres=#
postgres=#
Related examples in the same category