Diagnostic Queries
Symptoms
An operation that needs equality (DISTINCT, GROUP BY, UNION, a hash/sort step) was applied to a type that has no equality operator. PostgreSQL raises SQLSTATE 42883 (undefined_function).
- The type lacks a defined
=operator. - Common with
json,xml, or custom types. - Triggered by DISTINCT/GROUP BY/UNION on such a type.
What the server log shows
ERROR: could not identify an equality operator for type json
Why PostgreSQL raises this — what the manual says
As Section 8.14 JSON Types explains:
The operation (DISTINCT, GROUP BY, UNION, or similar) needed an equality operator, but the json type does not provide one; cast the values to jsonb, which supports equality and the comparison operators these operations require.
Set/grouping operations require an equality operator to compare values. For types that define none (like json), PostgreSQL cannot perform the comparison and reports 42883.
Common causes
DISTINCT/GROUP BY/UNIONon ajsoncolumn.- Comparing a custom type without an equality operator.
- Using such a type as a grouping or join key.
How to fix it
- Use
jsonbinstead ofjson— it supports equality. - Cast to a comparable type (e.g.
col::textorcol::jsonb). - Define an equality operator/operator class for custom types.
Related & next steps
Reference: PostgreSQL 18 Section 8.14 “JSON Types”.
Thanks — noted. This helps keep the database accurate.