# 42846 — Cannot coerce

> PostgreSQL SQLSTATE 42846: Cannot coerce (cannot_coerce), source-backed diagnosis and recovery guidance.
---

# 42846 — Cannot coerce

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

`42846` is **cannot_coerce**: no applicable cast connects the source and target types. The selected expression asks for `integer` to `date`.

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

| Field | Value |
| --- | --- |
| SQLSTATE | `42846` |
| Condition | `cannot_coerce` |
| 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_CANNOT_COERCE` |
| Aliases | `—` |

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

## Meaning {#meaning}

The fixed primary is `cannot cast type %s to %s`. It is not `22P02` (a bad value for a valid cast) or `42804` (an expression type mismatch in a target context). Inspect `pg_cast` and the expression context; the selected autocommit connection remains `IDLE` after the impossible cast.

## Diagnosis {#diagnosis}

Read both source and target types from the diagnostic and inspect pg_cast and the expression context. Confirm whether the application needs a typed literal or a documented conversion function.

## Response {#response}

Construct a value in the target type or use a documented conversion function. The case uses `DATE '2026-01-01'`; it does not invent an integer-to-date business mapping or hide input errors with NULLIF. In an explicit transaction, the failed cast leaves `INERROR`; roll back or return to a suitable savepoint before retrying. The selected autocommit path returns to `IDLE`.

## Observed diagnostics {#messages}

The selected `parse_expr.c` group is explicit `ERROR` with primary `cannot cast type %s to %s` and no detail or hint.

## Representative case {#case}

The registry evaluates `SELECT 1::integer::date`, then a date-typed literal and asserts the exact returned date.

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

```sql
SELECT 1::integer::date;
SELECT DATE '2026-01-01';
```

<!-- END SQLSTATE SNIPPET -->

The selected 18.6 and 10.21 runs passed SQLSTATE, severity, state/recovery, repair, cleanup, and isolated-target stop assertions. See [`case JSON`](../data/cases/42846.json) and [`authored evidence`](../data/evidence/42846.json); private manifest and registry hashes are recorded there.

## Versions {#versions}

The locked catalogue contains this condition from the 7.4 presence bound through the listed snapshots. The selected natural case passed on PostgreSQL 18.6 and 10.21; that bounded result does not infer every intermediate release or every source branch.

## Related {#related}

- [`22P02`](../22p02/)
- [`42804`](../42804/)

## Sources {#sources}

- `src.errcodes.REL_18_6` — fixed definition at `724edf9bde9d356724ad384a2e196edc3c9f80f7`; SHA-256 `6e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba` ([source](https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/errcodes.txt#L1-L1)).
- `src.cannot-coerce.18.6` — `src/backend/parser/parse_expr.c` lines 2782–2787 at `724edf9bde9d356724ad384a2e196edc3c9f80f7`; blob SHA-256 `63c37770872a08978f931c31f801666a08e3bc8e51c2c65ff60151a1d139d55b` ([source](https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/parser/parse_expr.c#L2782-L2787)).
- `src.cannot-coerce.10.23` — `src/backend/parser/parse_expr.c` lines 2739–2744 at `02991e79f8f58bc208f05dcc8af0c62dbe0a6ea4`; blob SHA-256 `2700ba4a37d0715b66be76c900c7da7cf6a4d818eb71178e7b9a51e48e59e136` ([source](https://github.com/postgres/postgres/blob/02991e79f8f58bc208f05dcc8af0c62dbe0a6ea4/src/backend/parser/parse_expr.c#L2739-L2744)).
- `src.calls.REL_18_6` / `src.calls.REL_10_23` — fixed call scans, SHA-256 `9ee8a0e81d8f0825c5c1ae45583439859a26e602bdd4ce2f2a62aa278867ccbf` / `00d16d3eb01b71ccf1b245c8f3102f9d0ec9f36fb02777b8dd1b99fcb263040c`.
- `manifest.42846` / `snippet-registry.42846` — hashes are recorded in `evidence/42846.json` and each runtime record.
