42602
PostgreSQLERRORNotableSyntax Error or Access Rule ViolationHIGH confidence

invalid name

What this means

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.

Why it happens
  1. 1An identifier starts with a digit without being quoted
  2. 2An identifier contains special characters that are not permitted in unquoted identifiers
  3. 3Empty identifier (zero-length name) provided
How to reproduce

Creating a table with an invalid unquoted name.

trigger — this will error
trigger — this will error
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.

Quote the identifier with double quotes
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.

Rename to a valid unquoted identifier
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.

What not to do

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.

Sources
Official documentation ↗

Class 42 — Syntax Error or Access Rule Violation

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All PostgreSQL errors