All rules

Schema

postgresql/prefer-bigint-id

Prefer `bigint` for primary-key `id` columns; `int` overflows at 2.1B rows.

  • Type suggestion
  • Recommended warn
  • Fixable no

Why this matters

An `int` primary key overflows at ~2.1 billion rows. Widening the type later requires a table rewrite under `ACCESS EXCLUSIVE`. Declare the primary key as `bigint GENERATED ALWAYS AS IDENTITY` from the start. UUID primary keys and non-PK `id` columns are not flagged.

Examples

Incorrect

Incorrect
CREATE TABLE users (id int PRIMARY KEY, name text);
Incorrect
CREATE TABLE users (id serial PRIMARY KEY, name text);
Incorrect
CREATE TABLE users (id int, name text, PRIMARY KEY (id));

Correct

Correct
CREATE TABLE users (id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY, name text);
Correct
CREATE TABLE users (id uuid PRIMARY KEY, name text);

Configure it

// eslint.config.js
import postgresql from "eslint-plugin-postgresql";

export default [
  {
    files: ["**/*.sql"],
    languageOptions: {
      parser: postgresql.configs.recommended.languageOptions.parser,
    },
    plugins: { postgresql },
    rules: {
      "postgresql/prefer-bigint-id": "warn",
    },
  },
];

Options

This rule has no options.

Try this rule

Edit the SQL — only prefer-bigint-id is enabled.

Pre-filled with the first incorrect example. Toggle off in the rule shelf to see how the diagnostic disappears.

0 errors 0 warnings parse 0ms · rules 0ms
Diagnostics

No issues found.

2 rules enabled.

Rule under test prefer-bigint-id — plus no-syntax-error as a safety net.
eslint-plugin-postgresql

An ESLint plugin that lints .sql files with real PostgreSQL grammar and a curated set of best-practice rules.

© 2026 eslint-plugin-postgresql contributors Built on libpg-query · PostgreSQL 17