BIGSERIAL is a PostgreSQL pseudo-type for automatically generated 64-bit integer identifiers. PostgreSQL backs the column with a sequence, making it useful when an application may outgrow the 32-bit range provided by SERIAL. section 2.1.3 section 11.2
Use BIGSERIAL when:
- A table needs automatically assigned numeric primary keys. section 2.1.3
- The expected identifier range may exceed SERIAL’s 32-bit capacity; BIGSERIAL supports 64-bit integers up to 9,223,372,036,854,775,807. section 2.1.3
- A queue needs monotonically generated message IDs for identifying and ordering records. section 11.2
Create a reviews table
CREATE TABLE products.reviews ( id BIGSERIAL PRIMARY KEY, product_id INT, customer_id INT, review TEXT, rank SMALLINT ); PostgreSQL creates the table’s identifier column and an associated sequence, visible with the psql \d command. Inserts can omit id; the sequence supplies it automatically.
Each concurrent producer may wait for the sequence to generate the next ID. If sequence generation becomes a bottleneck, UUIDs provide an alternative identifier strategy. section 11.2
