# 42602 — invalid_name

> PostgreSQL SQLSTATE 42602: invalid_name, source-backed diagnosis and recovery guidance.
---

# 42602

## At a glance {#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.

<!-- BEGIN SQLSTATE FACTS: generated by scripts/generate.py; do not edit -->

| Field | Value |
| --- | --- |
| SQLSTATE | `42602` |
| Condition | `invalid_name` |
| Status | `active` |
| Known present by | `7.4` |
| Locked snapshots | `9.0.23, 9.1.24, 9.2.24, 9.3.25, 9.4.26, 9.5.25, 9.6.24, 10.23, 11.22, 12.22, 13.23, 14.24, 15.19, 16.15, 17.11, 18.6, 19beta3` |
| Macros | `ERRCODE_INVALID_NAME` |
| Aliases | `—` |

<!-- source facts: data/errcodes/42602.json -->
<!-- END SQLSTATE FACTS -->

## Meaning {#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 {#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 {#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 {#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 {#case}

<!-- BEGIN SQLSTATE SNIPPET: invalid_enum_label -->

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.

```sql
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[];
```

<!-- END SQLSTATE SNIPPET -->

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`](../data/cases/42602.json) and [`authored evidence`](../data/evidence/42602.json). The runner manifest is `verify/cases/42602/cases.json`, and the page SQL is checked against its shared registry.

## Versions {#versions}

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

## Related {#related}

- [`42622` — name_too_long](../42622/)

## Sources {#sources}

- `src.errcodes.18.6` — fixed `errcodes.txt` definition at commit `724edf9bde9d356724ad384a2e196edc3c9f80f7`; SHA-256 `6e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba` ([source](https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/errcodes.txt)).
- `src.enum-invalid-label.18.6` — `src/backend/catalog/pg_enum.c` at `REL_18_6` commit `724edf9bde9d356724ad384a2e196edc3c9f80f7`; fixed blob SHA-256 `849793e92baf9c0e4e8950f8472e2772289c22c58a4ea93997ef0218d7e4b3fc` ([source](https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/catalog/pg_enum.c#L312-L316)).
- `src.enum-invalid-label.10.23` — `src/backend/catalog/pg_enum.c` at `REL_10_23` commit `02991e79f8f58bc208f05dcc8af0c62dbe0a6ea4`; fixed blob SHA-256 `08076bbd661f4c400cf9741f4cfe89c5b0daf3383e4a3e6ac10f3f8f4bec16a6` ([source](https://github.com/postgres/postgres/blob/02991e79f8f58bc208f05dcc8af0c62dbe0a6ea4/src/backend/catalog/pg_enum.c#L199-L203)).
- `src.calls.REL_18_6` / `src.calls.REL_10_23` — fixed call scans, SHA-256 `9ee8a0e81d8f0825c5c1ae45583439859a26e602bdd4ce2f2a62aa278867ccbf` / `00d16d3eb01b71ccf1b245c8f3102f9d0ec9f36fb02777b8dd1b99fcb263040c`.
