Diagnostic Queries
Symptoms
An operator call matched more than one candidate operator and PostgreSQL could not choose a single best match. It refuses to guess and raises SQLSTATE 42725 (ambiguous_function).
- Usually involves untyped literals or parameters with several plausible coercions.
- A HINT suggests adding explicit casts.
- Closely related to 42883 (no operator) but here there are too many.
What the server log shows
ERROR: operator is not unique: unknown || unknown
LINE 1: SELECT $1 || $2;
^
HINT: Could not choose a best candidate operator. You might need to add explicit type casts.
Why PostgreSQL raises this — what the manual says
As Section 10.2 Operators explains:
More than one candidate operator matched the call equally well after type-conversion rules were applied, so PostgreSQL could not choose a single best match; add an explicit cast on one operand to disambiguate.
Operator resolution narrows candidates by exact and implicit-cast matches, then by preferred types. If several equally-good candidates remain — common when operands are unknown (untyped literals) or parameters — the system cannot pick one and reports 42725.
Common causes
- Concatenating or comparing two untyped literals/parameters.
- A user-defined operator overlapping a built-in for the same operand types.
- Ambiguous numeric vs text coercion paths.
How to fix it
- Cast operands to concrete types:
$1::text || $2::text. - Type at least one side so preferred-type rules can resolve the rest.
- Avoid defining overlapping custom operators, or schema-qualify the intended one.
Related & next steps
Reference: PostgreSQL 18 Section 10.2 “Operators”.
Thanks — noted. This helps keep the database accurate.