type creates and uses a sequence behing the scenes, but its operation is transparent to you. You do not need to create an additional sequence to use it. See... (using psql, Postgres's command line
test=# create table foo(ID serial NOT NULL,bar text, constraint foo_pk primary key (ID));
NOTICE: CREATE TABLE will create implicit sequence 'foo_id_seq' for SERIAL column 'foo.id'
NOTICE: CREATE TABLE/PRIMARY KEY will create implicit index 'foo_pk' for table 'foo'
test=# insert into foo (bar) values ('abc');
INSERT 27135 1
test=# insert into foo (bar) values ('def');
INSERT 27136 1
test=# select * from foo;
id | bar
1 | abc
2 | def
I find postgres sequence
s to be most useful when you want to
share one unique ID across tables and when you don't have a master table to store it in (or don't have a table that will always be inserted first
). Or when you want to assign something outside of the DB (at least at the time of assignment) a unique ID.