All rules
Safety
postgresql/
Disallow identifiers longer than PostgreSQL's `NAMEDATALEN - 1` limit (default 63 bytes).
Why this matters
PostgreSQL stores identifiers in a fixed-width `name` column whose size is `NAMEDATALEN` (64 by default). Anything longer than `NAMEDATALEN - 1` bytes is **silently truncated** at parse time, so the object is created under a different name than written. Every later `DROP CONSTRAINT` / `ALTER ... RENAME` / `\d` that uses the original name then fails with `does not exist`. Bytes — not characters — count, so a 22-character CJK name is already over the limit.
Examples
Incorrect
CREATE TABLE this_is_a_very_very_very_very_very_very_very_very_long_table (id bigserial PRIMARY KEY);ALTER TABLE items
ADD CONSTRAINT items_code_check_that_is_unfortunately_far_too_long_for_postgresql CHECK (length(code) > 0);CREATE INDEX an_index_name_that_exceeds_the_sixty_three_byte_postgres_limit ON items (code);Correct
CREATE TABLE long_but_within_limit_table (id bigserial PRIMARY KEY);ALTER TABLE items ADD CONSTRAINT items_code_non_empty CHECK (length(code) > 0);CREATE INDEX items_code_idx ON items (code);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-identifier-too-long": [
"error",
{
max: 63,
},
],
},
},
]; Options
Edit the SQL — only no-identifier-too-long 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-identifier-too-long — plus no-syntax-error as a safety net.