ERROR: column "x" is of type integer but expression is of type text — HINT: You will need to rewrite or cast the expression.

An INSERT/UPDATE supplies a value of a different type than the column, and PostgreSQL won’t cast implicitly.

Seen on: PostgreSQL

Meaning

Parameters bound as text, jsonb vs json, or enum columns receiving text. Explicit casts fix it.

Common causes

  • Parameters sent as strings
  • Enum column receiving text without cast
  • json vs jsonb mismatch

⚡ Quick fix

  1. Cast: $1::int / $1::my_enum
  2. Fix the driver/ORM type mapping

Detailed fix by platform

PostgreSQL

  1. UPDATE orders SET status = $1::order_status WHERE id = $2;

How to diagnose

  1. Types — Column type vs expression type
  2. Recent change — Did it start after a deploy, upgrade, or configuration change? Compare with the last working version.

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.