Diagnostic Queries
Symptoms
A string operation combined values with conflicting (or indeterminate) collations and PostgreSQL could not choose one. It raises SQLSTATE 42P22 (indeterminate_collation).
- Two operands carry different explicit collations.
- A HINT suggests using an explicit
COLLATEclause. - Common when comparing columns from different collations.
What the server log shows
ERROR: could not determine which collation to use for string comparison
HINT: Use the COLLATE clause to set the collation explicitly.
Why PostgreSQL raises this — what the manual says
Section 24.2 Collation Support (Collation Concepts):
“If there are conflicting non-default implicit collations among the input expressions, then the combination is deemed to have indeterminate collation.”
Each string expression has a collation derivation. When an operation combines two explicit, conflicting collations, the result is indeterminate and PostgreSQL refuses to guess, reporting 42P22.
Common causes
- Comparing/concatenating columns with different explicit collations.
- Mixing collations in an expression without an override.
- Functions receiving operands of conflicting collations.
How to fix it
- Add an explicit
COLLATEto one operand:a = b COLLATE "en_US". - Normalize collations on the columns involved.
- Apply the same COLLATE to all string operands in the expression.
Related & next steps
Reference: PostgreSQL 18 Section 24.2 “Collation Support”.
Thanks — noted. This helps keep the database accurate.