invalid input syntax for type boolean: “…”

SQLSTATE 22P02 condition invalid_text_representation class 22 — Data Exception severity ERROR
Reproduced & verified on PostgreSQL 14.23, 15.18, 16.14, 17.10 and 18.4 — identical message on every version.
Last reviewed 30 May 2025 · Reproduced live with the SQL on this page.

Symptoms

A value being converted to boolean is not a recognized boolean literal. PostgreSQL raises SQLSTATE 22P02 (invalid_text_representation).

What the server log shows

ERROR:  invalid input syntax for type boolean: "Y"

Why PostgreSQL raises this — what the manual says

Section 8.6 Boolean Type:

“Boolean constants can be represented in SQL queries by the SQL key words TRUE, FALSE, and NULL.”

The boolean input function only recognizes a fixed set of case-insensitive literals (and their unique prefixes). Anything outside that set has no boolean meaning and fails with 22P02.

Common causes

How to fix it

  1. Map values to accepted literals (true/false, t/f, 1/0) before insert.
  2. Use a CASE expression to translate custom codes: CASE flag WHEN 'Y' THEN true ELSE false END.
  3. Convert empty strings to NULL.

Related & next steps

Reference: PostgreSQL 18 Section 8.6 “Boolean Type”.