Skip to main content

bigint

Learning Focus

Use this lesson to choose PostgreSQL bigint when you need long-term safety for IDs and high-volume counters.

bigint Overview

  • Storage: 8 bytes
  • Range: -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
  • Best for: long-lived primary keys, event counters at scale

Example

CREATE TABLE events (
event_id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
created_at timestamptz NOT NULL DEFAULT now()
);

Best Practices

  • Prefer bigint for primary keys in systems expected to grow for years.
  • Use identity columns (GENERATED AS IDENTITY) rather than manual sequence management.

What's Next