42622ERRORTier 2 — Caution✅ HIGH confidencename too long
What this means
SQLSTATE 42622 is raised when an identifier (table name, column name, constraint name, etc.) exceeds the maximum length allowed by Postgres. By default, the maximum identifier length is 63 bytes (NAMEDATALEN - 1).
Why it happens
- 1An identifier exceeds 63 bytes (the default NAMEDATALEN limit)
- 2Auto-generated constraint names (e.g., from long table and column name combinations) exceed 63 bytes
How to reproduce
Creating a column with a name exceeding 63 bytes.
CREATE TABLE t (
this_column_name_is_way_too_long_to_fit_in_the_postgres_name_limit_of_63_bytes TEXT
);Fix 1: Shorten the identifier to 63 bytes or fewer
When creating long-named objects.
CREATE TABLE t (
long_description_column TEXT -- shortened
);Why this works
Postgres silently truncates identifiers that are too long (with a warning). To avoid the truncation and potential name collisions, use explicitly shorter names.
Fix 2: Explicitly name auto-generated constraints with short names
When auto-generated constraint names may be too long.
ALTER TABLE orders ADD CONSTRAINT fk_orders_cust
FOREIGN KEY (customer_id) REFERENCES customers(id);Why this works
Providing an explicit short constraint name prevents auto-generated names from being truncated in ways that may clash.
Version notes
All versionsNAMEDATALEN is a compile-time constant defaulting to 64 (max identifier = 63 bytes). Rebuilding Postgres from source with a higher NAMEDATALEN is possible but non-standard.Sources
📚 Official docs: https://www.postgresql.org/docs/current/errcodes-appendix.html
🔧 Source ref: Class 42 — Syntax Error or Access Rule Violation
Confidence assessment
✅ HIGH confidence
Standard SQLSTATE. The 63-byte limit is consistent across all versions with default NAMEDATALEN.
See also
🔗 Related errors
📄 Reference pages