invalid name
SQLSTATE 42602 is raised when an identifier (table name, column name, role name, etc.) is syntactically invalid — for example, it contains illegal characters or starts with a digit.
- 1An identifier starts with a digit without being quoted
- 2An identifier contains special characters that are not permitted in unquoted identifiers
- 3Empty identifier (zero-length name) provided
Creating a table with an invalid unquoted name.
CREATE TABLE 123bad (id INT); -- starts with digit
expected output
ERROR: invalid name syntax
Fix 1
Quote the identifier with double quotes
WHEN When using unconventional identifier names is required.
CREATE TABLE "123bad" (id INT);
Why this works
Double-quoting allows any characters in an identifier, including leading digits, spaces, and special characters. Note that quoted identifiers are case-sensitive.
Fix 2
Rename to a valid unquoted identifier
WHEN When the identifier name can be changed.
CREATE TABLE bad_123 (id INT); -- valid: starts with letter
Why this works
Unquoted identifiers must start with a letter or underscore and contain only letters, digits, underscores, and dollar signs.
✕ Use quoted identifiers for all identifiers by default
Quoted identifiers are case-sensitive, which can cause surprising behaviour when mixed with case-insensitive unquoted identifiers.
Class 42 — Syntax Error or Access Rule Violation
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev