All rules
Schema
postgresql/
Enforce a consistent stance on `GENERATED ... AS IDENTITY` vs `SERIAL` / `BIGSERIAL`.
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
CREATE TABLE t (id BIGSERIAL);CREATE TABLE t (id SERIAL);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
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.
Diagnostics
No issues found.
2 rules enabled.
Rule under test
consistent-identity-over-serial — plus no-syntax-error as a safety net.