42P10 — Invalid column reference
42P10 — Invalid column reference
At a glance
42P10 (invalid_column_reference) Column references can be rejected by the operation that consumes them.
| Field | Value |
|---|---|
| SQLSTATE | 42P10 |
| Condition | invalid_column_reference |
| 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_COLUMN_REFERENCE |
| Aliases | — |
Meaning
Several consumers use 42P10 for different column-reference contracts. In the selected 18.6 paths, cookConstraint permits only the table that owns a CHECK constraint, CopyGetAttnums rejects a generated column named in an explicit COPY list (the default list skips generated columns), and ON CONFLICT inference reports this code when no suitable arbiter index matches. The last path is an inference failure, not a generic missing-column error.
Diagnosis
Read the complete primary message and DETAIL, then identify the statement phase: CHECK constraint ownership, an explicit COPY column list, or ON CONFLICT arbiter inference. For COPY, distinguish a user-supplied list from the default list. For ON CONFLICT, inspect the action and the candidate index’s columns or expressions, predicate, collation, and operator class; DO UPDATE needs a matching unique arbiter, while an exclusion constraint is not a general substitute for that action. Do not diagnose this as a missing column without the phase-specific message.
Response
Repair the specific contract: define the CHECK on its owning table, omit generated columns from an explicit COPY list, or align ON CONFLICT with an existing suitable unique index/constraint and its inference details. For DO NOTHING, verify the action-specific arbiter rules before considering an exclusion constraint. Do not create an arbitrary constraint as a generic repair. If this ERROR occurs inside an explicit transaction, ROLLBACK before the next command or ROLLBACK TO a savepoint created before the statement, then retry only after checking the catalog.
Messages
Representative source messages include: message: only table "%s" can be referenced in check constraint; message: column "%s" is a generated column; DETAIL: Generated columns cannot be used in COPY.; message: there is no unique or exclusion constraint matching the ON CONFLICT specification. Placeholders are filled by the actual object, column, or parameter.
Versions
The locked catalogue shows this condition by PostgreSQL 7.4; behavior here is fixed to PostgreSQL 18.6 source. Catalogue presence is a range boundary, not proof that every message or feature began in that release.
Related
Sources
Source messages, line anchors, and evidence limits are recorded in authored evidence.
src/backend/catalog/heap.c:3465-3468(fixed source)src/backend/commands/copy.c:1026-1030(fixed source)src/backend/optimizer/util/plancat.c:958-960(fixed source)