serial
is a pseudo data type, not an actual data type. It's an integer
underneath with some additional DDL commands executed automatically:
- Create a
SEQUENCE
(with matching name by default).
- Set the column
NOT NULL
and the default to draw from that sequence.
- Make the column "own" the sequence.
Details:
A bigserial
is the same, built around a bigint
column. You want bigint
, but you already achieved that. To transform an existing serial
column into a bigserial
(or smallserial
), all you need to do is ALTER
the data type of the column. Sequences are generally based on bigint
, so the same sequence can be used for any integer
type.
To "change" a bigint
into a bigserial
or an integer
into a serial
, you just have to do the rest by hand:
The actual data type is still integer
/ bigint
. Some clients like pgAdmin will display the data type serial
in the reverse engineered CREATE TABLE
script, if all criteria for a serial
are met.