SQLSTATE 42804 ERROR Class 42: Syntax Error or Access Rule Violation

datatype_mismatch argument of WHERE must be type boolean, not type … — 42804

PostgreSQL error "argument of WHERE must be type boolean, not type …" (SQLSTATE 42804): what it means, common causes, and how to fix it.

PG 12, 13, 14, 15, 16, 17, 18 Official docs
Last reviewed May 2025 Grounded in source

Diagnostic Queries

Symptoms

The expression in a WHERE (or HAVING/CHECK/ON) clause did not evaluate to boolean. PostgreSQL is strict about boolean context and raises SQLSTATE 42804 (datatype_mismatch).

  • Often from WHERE flag = 1 on a non-boolean integer, or WHERE somecolumn that is text.
  • The message names the offending type, e.g. integer.
  • PostgreSQL does not implicitly treat non-zero numbers as true.

What the server log shows

ERROR:  argument of WHERE must be type boolean, not type integer
LINE 1: SELECT * FROM t WHERE 1;
                              ^

Why PostgreSQL raises this — what the manual says

As Section 9.1 Logical Operators explains:

A WHERE, HAVING, or CHECK condition must evaluate to the boolean type, but the supplied expression has some other type; turn it into a comparison (for example col = value or col IS NOT NULL) or cast it explicitly to boolean.

WHERE filters rows by evaluating a boolean predicate per row. PostgreSQL does not coerce integers or strings to boolean, so a non-boolean expression in that position is a type mismatch and fails with 42804.

Common causes

  • Treating an integer/text column as a truthy flag (WHERE active where active is int).
  • Forgetting the comparison operator (WHERE status instead of WHERE status = 'open').
  • Porting code from a database with truthy semantics.

How to fix it

  1. Write an explicit comparison: WHERE active = 1 or WHERE active <> 0.
  2. Use a real boolean column/type where you want truthiness.
  3. Cast intentionally if needed: WHERE (active)::boolean (note: only 0/1-style ints cast cleanly).

Related & next steps

Reference: PostgreSQL 18 Section 9.1 “Logical Operators”.

Was this helpful?