All rules

Schema

postgresql/consistent-identity-over-serial

Enforce a consistent stance on `GENERATED ... AS IDENTITY` vs `SERIAL` / `BIGSERIAL`.

  • Type suggestion
  • Recommended warn
  • Fixable no

Why this matters

Serial pseudo-types create a separately-owned sequence that does not round-trip cleanly through `pg_dump` and does not honor column-level privileges. `GENERATED ... AS IDENTITY` is the SQL-standard replacement and has been the PostgreSQL team's recommendation since version 10. Pick one direction with the `style` option.

Examples

Incorrect

Incorrect
CREATE TABLE t (id BIGSERIAL);
Incorrect
CREATE TABLE t (id SERIAL);

Correct

Correct
CREATE TABLE t (id BIGINT GENERATED ALWAYS AS IDENTITY);

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/consistent-identity-over-serial": [
        "warn",
        {
          style: "always",
        },
      ],
    },
  },
];

Options

style "always" | "never" default: "always"
`always` (default) requires identity columns over serial pseudo-types. `never` requires the serial pseudo-types for projects that keep compatibility with tooling that does not understand identity columns.
Try this rule

Edit the SQL — only consistent-identity-over-serial 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 consistent-identity-over-serial — 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