42846 — Cannot coerce
42846 — Cannot coerce
At a glance
42846 is cannot_coerce: no applicable cast connects the source and target types. The selected expression asks for integer to date.
| 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 | — |
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
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
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
The selected parse_expr.c group is explicit ERROR with primary cannot cast type %s to %s and no detail or hint.
Representative case
The registry evaluates SELECT 1::integer::date, then a date-typed literal and asserts the exact returned date.
The selected 18.6 and 10.21 runs passed SQLSTATE, severity, state/recovery, repair, cleanup, and isolated-target stop assertions. See case JSON and authored evidence; private manifest and registry hashes are recorded there.
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
Sources
src.errcodes.REL_18_6— fixed definition at724edf9bde9d356724ad384a2e196edc3c9f80f7; SHA-2566e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba(source).src.cannot-coerce.18.6—src/backend/parser/parse_expr.clines 2782–2787 at724edf9bde9d356724ad384a2e196edc3c9f80f7; blob SHA-25663c37770872a08978f931c31f801666a08e3bc8e51c2c65ff60151a1d139d55b(source).src.cannot-coerce.10.23—src/backend/parser/parse_expr.clines 2739–2744 at02991e79f8f58bc208f05dcc8af0c62dbe0a6ea4; blob SHA-2562700ba4a37d0715b66be76c900c7da7cf6a4d818eb71178e7b9a51e48e59e136(source).src.calls.REL_18_6/src.calls.REL_10_23— fixed call scans, SHA-2569ee8a0e81d8f0825c5c1ae45583439859a26e602bdd4ce2f2a62aa278867ccbf/00d16d3eb01b71ccf1b245c8f3102f9d0ec9f36fb02777b8dd1b99fcb263040c.manifest.42846/snippet-registry.42846— hashes are recorded inevidence/42846.jsonand each runtime record.