select open change scope Open full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

SQLSTATE / CLASS 42 · SYNTAX ERROR OR ACCESS RULE VIOLATION

invalid_name

SQLSTATE
42602
Condition name
invalid_name
Class
Syntax Error or Access Rule Violation
Source macro
ERRCODE_INVALID_NAME
Evidence
Observed at runtime in the source evidence
Analysis & operational context

English SQLSTATE atlas: authored explanations and source/runtime evidence are separate from the manual definitions. View source ↗

<h1>42602</h1>

At a glance

SQLSTATE 42602 is invalid_name in Class 42. 42602 is an invalid name. The selected enum path rejects a 64-byte label with primary invalid enum label "%s" and a length detail; a short label can be added afterwards.

Meaning

42602 is an invalid name. In AddEnumLabel, PostgreSQL checks the incoming enum label against NAMEDATALEN - 1 before changing the catalog. The selected 64-byte label therefore raises an explicit ERROR with primary invalid enum label "%s" and a length DETAIL; a short label can be added afterwards. This is the enum-label path, not a claim that every invalid object name uses the same producer.

Diagnosis

Inspect the object kind and the exact length wording in the DETAIL. This batch observes the enum-label path on 18.6 and 10.21: the 18.6 source/runtime says Labels must be 63 bytes or less., while the 10.21 source/runtime says Labels must be 63 characters or less. That wording difference alone does not establish a changed length mechanism; both fixed guards compare the label against NAMEDATALEN - 1. The failed DDL is an ERROR on autocommit and leaves the selected session IDLE.

Response

Choose a label within the server limit or store the long user value as data. Preserve the enum type and add a valid short label only after the failed statement has returned; the selected repair leaves the type with ok and short. Do not silently truncate enum labels or treat this enum-specific path as every possible naming error.

Messages

The selected source path emits an explicit ERROR with primary invalid enum label "%s". Its DETAIL is Labels must be 63 bytes or less. on 18.6 and Labels must be 63 characters or less. on 10.21; the label text is dynamic. A client exception without the server SQLSTATE, primary, and length DETAIL is not sufficient to identify this selected enum-label subpath; other fixed producers can use the same SQLSTATE with different diagnostics.

Representative case

The page uses the same statements as the runner registry. Generated names such as syntax_schema and syntax_role are replaced by disposable runner values when executed.

CREATE TYPE syntax_schema.syntax_enum AS ENUM ('ok');
ALTER TYPE syntax_schema.syntax_enum ADD VALUE 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
ALTER TYPE syntax_schema.syntax_enum ADD VALUE 'short';
SELECT enum_range(NULL::syntax_schema.syntax_enum)::text[];

The selected 18.6 run reports the structured diagnostic and passes the repair assertions; the 10.21 run passes the same case-specific checks. The downloadable case and evidence projections are 42602 case JSON and authored evidence. The runner manifest is verify/cases/42602/cases.json, and the page SQL is checked against its shared registry.

Versions

The selected natural runtime scope is PostgreSQL 18.6 and 10.21; it does not infer behavior for every intermediate release.

Sources

  • src.errcodes.18.6 — fixed errcodes.txt definition at commit 724edf9bde9d356724ad384a2e196edc3c9f80f7; SHA-256 6e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba (source).
  • src.enum-invalid-label.18.6src/backend/catalog/pg_enum.c at REL_18_6 commit 724edf9bde9d356724ad384a2e196edc3c9f80f7; fixed blob SHA-256 849793e92baf9c0e4e8950f8472e2772289c22c58a4ea93997ef0218d7e4b3fc (source).
  • src.enum-invalid-label.10.23src/backend/catalog/pg_enum.c at REL_10_23 commit 02991e79f8f58bc208f05dcc8af0c62dbe0a6ea4; fixed blob SHA-256 08076bbd661f4c400cf9741f4cfe89c5b0daf3383e4a3e6ac10f3f8f4bec16a6 (source).
  • src.calls.REL_18_6 / src.calls.REL_10_23 — fixed call scans, SHA-256 9ee8a0e81d8f0825c5c1ae45583439859a26e602bdd4ce2f2a62aa278867ccbf / 00d16d3eb01b71ccf1b245c8f3102f9d0ec9f36fb02777b8dd1b99fcb263040c.

Source evidence

Evidence belongs to the frozen source and runtime versions listed here. It is not a runtime verification of the selected manual version.

42602 is the invalid_name condition in Class 42.

Method: Read fixed errcodes.txt and the locked catalogue metadata.

Limits: Directory identity does not identify every backend path.

src.errcodes.18.6

The fixed source calls for 42602 include the mechanism and message boundary selected for this page.

Method: Trace the resolved REL_18_6 and REL_10_23 source call records at the locked commits.

Limits: Other calls can use the same SQLSTATE with different context or dynamic fields.

src.enum-invalid-label.18.6 src.enum-invalid-label.10.23

The selected invalid_enum_label case passed on isolated PostgreSQL 18.6 and 10.21 targets.

Method: Run the shared registry case and inspect structured diagnostics, state/recovery assertions, and cleanup.

Limits: This covers the selected case and targets only; it does not generalize to all drivers or intermediate releases.

manifest.42602 snippet-registry.42602

The locked catalogue records 42602; runtime scope is limited to the selected targets.

Method: Read generated facts and selected summaries.

Limits: Definition presence is not an exact behavioral introduction.

src.errcodes.18.6 src.calls.REL_18_6 src.calls.REL_10_23

Message templates

explicit ERROR · message.enum-label

Primary

invalid enum label "%s"

Detail

Labels must be %d bytes or less.

Detail

Labels must be %d characters or less.

Reproduction & repair cases

invalid_enum_label · PG 10, 18

Preconditions

  • A runner-owned disposable target is provisioned.

Trigger: Create an enum and add a 64-byte label, exceeding the enum label limit.

Expected assertions

  • SQLSTATE is 42602 and the primary identifies an invalid enum label
  • The session remains IDLE
  • Adding a short label succeeds and the enum contains both labels

Repair: Use an enum label within the server byte limit or model longer values as data.

Cleanup: Drop the case schema with an owner connection.

Recorded runtime evidence

18.6 (Homebrew) · passed

Run: 42602-syntax-latest1

{
  "labels": [
    "ok",
    "short"
  ],
  "diagnostic": {
    "text": "invalid enum label \"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\"\nDETAIL:  Labels must be 63 bytes or less.",
    "context": null,
    "severity": "ERROR",
    "sqlstate": "42602",
    "table_name": null,
    "column_name": null,
    "schema_name": null,
    "source_file": "pg_enum.c",
    "source_line": "316",
    "message_hint": null,
    "datatype_name": null,
    "exception_type": "InvalidName",
    "internal_query": null,
    "message_detail": "Labels must be 63 bytes or less.",
    "constraint_name": null,
    "message_primary": "invalid enum label \"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\"",
    "source_function": "AddEnumLabel",
    "internal_position": null,
    "statement_position": null,
    "severity_nonlocalized": "ERROR"
  },
  "failed_status": "IDLE",
  "repair_status": "IDLE",
  "connection_autocommit": true
}
10.21 (Debian 10.21-1.pgdg90+1) · passed

Run: 42602-syntax-pg10

{
  "labels": [
    "ok",
    "short"
  ],
  "diagnostic": {
    "text": "invalid enum label \"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\"\nDETAIL:  Labels must be 63 characters or less.",
    "context": null,
    "severity": "ERROR",
    "sqlstate": "42602",
    "table_name": null,
    "column_name": null,
    "schema_name": null,
    "source_file": "pg_enum.c",
    "source_line": "203",
    "message_hint": null,
    "datatype_name": null,
    "exception_type": "InvalidName",
    "internal_query": null,
    "message_detail": "Labels must be 63 characters or less.",
    "constraint_name": null,
    "message_primary": "invalid enum label \"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\"",
    "source_function": "AddEnumLabel",
    "internal_position": null,
    "statement_position": null,
    "severity_nonlocalized": "ERROR"
  },
  "failed_status": "IDLE",
  "repair_status": "IDLE",
  "connection_autocommit": true
}

Definition snapshot: english-manuals:0be3241c1a097361360d5412cc2… · English manual source