# 42P10 — Invalid column reference

> Source-backed reference for PostgreSQL SQLSTATE 42P10.
---

# 42P10 — Invalid column reference

## At a glance {#at-a-glance}

`42P10` (**invalid_column_reference**) Column references can be rejected by the operation that consumes them.

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

| 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 | `—` |

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

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

- [`42P11`](../42p11/)
- [`42P18`](../42p18/)

## Sources {#sources}

Source messages, line anchors, and evidence limits are recorded in [authored evidence](../data/evidence/42p10.json).

- `src/backend/catalog/heap.c:3465-3468` ([fixed source](https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/catalog/heap.c#L3465-L3468))
- `src/backend/commands/copy.c:1026-1030` ([fixed source](https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/commands/copy.c#L1026-L1030))
- `src/backend/optimizer/util/plancat.c:958-960` ([fixed source](https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/optimizer/util/plancat.c#L958-L960))
