Why this matters
A composite PRIMARY KEY couples a row's identity to multiple business columns. Every foreign-key reference must repeat that column set, ORMs frequently misbehave on multi-column keys, and changing the natural key later requires rewriting both the table and every referrer. Use a single surrogate key (e.g. `id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY` or a UUID) and enforce the natural uniqueness with a `UNIQUE` constraint on the same columns.
Examples
Incorrect
CREATE TABLE memberships (user_id bigint, group_id bigint, PRIMARY KEY (user_id, group_id));ALTER TABLE memberships ADD CONSTRAINT memberships_pkey PRIMARY KEY (user_id, group_id);Correct
CREATE TABLE memberships (id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY, user_id bigint NOT NULL, group_id bigint NOT NULL, UNIQUE (user_id, group_id));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/no-composite-primary-key": "warn",
},
},
]; Options
Edit the SQL — only no-composite-primary-key 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
no-composite-primary-key — plus no-syntax-error as a safety net.