I am using postgresql, and was wondering how large
id INTEGER PRIMARY KEY
can get compared to
id SERIAL PRIMARY KEY
The data types smallserial, serial and bigserial are not true types, but merely a notational convenience for creating unique identifier columns (similar to the AUTO_INCREMENT property supported by some other databases)
A bigserial is 8 bytes long. If that is not enough it is possible to use the 128 bits uuid:
create table t (
id uuid primary key
);
insert into t (id)
select uuid_generate_v1mc();
select * from t;
id
--------------------------------------
916bf7e6-f0c2-11e2-8d14-d372d5ab075f
The uuid_generate_v1mc function is provided by the uuid-ossp module
The main advantage of the uuid functions is that they generate an id that is very likely to be unique among different systems. A serial will have collisions between those systems.