SQLSTATE 42846Severity lowLab verified

Incident brief

Cannot coerce

A value was cast to a type with no defined conversion path. PostgreSQL refused the cast instead of guessing at one.

Reproduced on PostgreSQL 16.14Verified 2026-07-16 (Docker lab, PostgreSQL 16.14)Reviewed by Verified against PostgreSQL 16.14 in an isolated lab environment

In 10 seconds

What
Cannot coerce
What triggers it
Cast a json value directly to a type with no defined json cast, such as integer.
The fix
Extract the specific field or value from the json first (with ->> or ->), then cast that extracted text.
Proof
Reproduced on PostgreSQL 16.14 → Casting a json object directly to integer was rejected with SQLSTATE 42846. The session was unaffected afterward.

The fix

What to do right now

The immediate, application-level response to this error.

  • Extract the specific field or value from the json first (with ->> or ->), then cast that extracted text.
  • Don't route the value through ::text as a generic bypass — see the counterexample for how that trades one error for a more confusing one.
  • For scalar-only json values, casting via ::text can appear to work, but it isn't a reliable general pattern.
Fix — SQL
SELECT ('{"a":1}'::json->>'a')::integer;

Related & next steps

Follow the thread

Everything this error touches — jump straight to the sibling error, term, runbook, or parameter.

Verification

PG 16.14
Last verified
2026-07-16 (Docker lab, PostgreSQL 16.14)
Reviewed by
Verified against PostgreSQL 16.14 in an isolated lab environment
Audit status
reviewed