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

undefined_function could not identify an equality operator for type … — 42883

PostgreSQL error "could not identify an equality operator for type …" (SQLSTATE 42883): 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

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/UNION on a json column.
  • Comparing a custom type without an equality operator.
  • Using such a type as a grouping or join key.

How to fix it

  1. Use jsonb instead of json — it supports equality.
  2. Cast to a comparable type (e.g. col::text or col::jsonb).
  3. Define an equality operator/operator class for custom types.

Related & next steps

Reference: PostgreSQL 18 Section 8.14 “JSON Types”.

Was this helpful?