42P21
Read PG 18 manual ↗collation_mismatch
- SQLSTATE
- 42P21
- Condition name
- collation_mismatch
- Class
- Syntax Error or Access Rule Violation
- Source macro
- ERRCODE_COLLATION_MISMATCH
- Evidence
- Source path confirmed
English SQLSTATE atlas: authored explanations and source/runtime evidence are separate from the manual definitions. View source ↗
At a glance
42P21 (collation_mismatch) Different collation choices meet where PostgreSQL requires one compatible result.
Meaning
42P21 is raised when a fixed-source path needs one compatible collation but has incompatible choices. Implicit choices are tracked as COLLATE_CONFLICT and may be returned as InvalidOid when the caller permits no common collation; a caller that requires a collation is where the implicit mismatch becomes an ERROR. Explicit COLLATE conflicts fail immediately. The same condition also covers recursive CTE output, inherited or child-column definitions, and foreign-key key-column compatibility.
Diagnosis
For an implicit-collation message, keep both names and inspect whether the caller requested a common collation; differing implicit operands do not all raise 42P21 immediately. For an explicit-collation message, find the two COLLATE clauses and make the intended choice consistent. In a recursive query compare the non-recursive term with the overall column collation. For inheritance or partitioned child errors compare the parent and child column definitions. For a foreign key compare the referencing and referenced key columns: fixed source permits different collations when both are deterministic, but if either is nondeterministic the two collations must be the same. Preserve the DETAIL names rather than treating this as a generic text-cast problem.
Response
Apply one deliberate COLLATE at the expression boundary for an expression conflict, or align the explicit clauses and recursive non-recursive term. Align inherited or child column definitions before rerunning DDL. For a foreign key, choose compatible key collations and satisfy the stricter same-collation rule whenever either side is nondeterministic; then recheck equality and index semantics. If this ERROR occurs inside an explicit transaction, issue ROLLBACK or ROLLBACK TO a pre-error savepoint before the corrected statement; autocommit can retry after returning to idle.
Messages
Representative fixed-source messages include:
- ERROR message:
collation mismatch between implicit collations "%s" and "%s"; HINT:You can choose the collation by applying the COLLATE clause to one or both expressions. - ERROR message:
collation mismatch between explicit collations "%s" and "%s" - ERROR message:
recursive query "%s" column %d has collation "%s" in non-recursive term but collation "%s" overall; HINT:Use the COLLATE clause to set the collation of the non-recursive term. - ERROR message:
column "%s" has a collation conflict; DETAIL:"%s" versus "%s" - ERROR message:
inherited column "%s" has a collation conflict; DETAIL:"%s" versus "%s" - ERROR message:
child table "%s" has different collation for column "%s"; DETAIL:"%s" versus "%s" - ERROR message:
foreign key constraint "%s" cannot be implemented; DETAIL:Key columns "%s" of the referencing table and "%s" of the referenced table have incompatible collations: "%s" and "%s". If either collation is nondeterministic, then both collations have to be the same.
Placeholders are filled by the actual object, column, or parameter.
Versions
The locked catalogue shows this condition by PostgreSQL 9.1.0; behavior here is fixed to PostgreSQL 18.6 source. Catalogue presence is a range boundary, not proof that every message or feature began in that release.
Sources
Source messages, line anchors, and evidence limits are recorded in authored evidence.
src/backend/parser/parse_collate.c:208-234(fixed source)src/backend/parser/parse_collate.c:804-835(fixed source)src/backend/parser/parse_cte.c:394-401(fixed source)src/backend/commands/tablecmds.c:3297-3303(fixed source)src/backend/commands/tablecmds.c:3463-3469(fixed source)src/backend/commands/tablecmds.c:7292-7298(fixed source)src/backend/commands/tablecmds.c:10474-10483(fixed source)
Source evidence
Evidence belongs to the frozen source and runtime versions listed here. It is not a runtime verification of the selected manual version.
42P21 is the collation_mismatch condition in Class 42.
Method: Read fixed REL_18_6 errcodes.txt and locked facts.
Limits: Identity does not enumerate all source branches or client failures.
Selected fixed 18.6 paths reject explicit collation conflicts immediately, emit implicit conflicts only when a caller requires one common collation, and check recursive output, inherited or child columns, and foreign-key collation compatibility.
Method: Read complete parse_collate.c derivation context and the selected resolved report groups in parse_cte.c and tablecmds.c.
Limits: Representative confirmed core paths only; not exhaustive historical or extension coverage.
src.call.42P21.69245d264e1d0e386e33036f src.call.42P21.0ba27778e76c3d44b1cc79f6 src.call.42P21.93a028fdb350e0d054f123d8 src.call.42P21.16107e45585553ed56b18241 src.call.42P21.5fcad21fbefb1ae15acf4c73 src.call.42P21.ef5edd918af762963c8e072c src.call.42P21.04a0360be247ab8ca050e826 src.context.42P21.parse_collate.common
select_common_collation(..., none_ok=true) may return InvalidOid while retaining an implicit COLLATE_CONFLICT; a later caller that requires a collation can then report a separate indeterminate-collation condition.
Method: Read select_common_collation and the COLLATE_CONFLICT/COLLATE_EXPLICIT branches in fixed parse_collate.c.
Limits: This is source control-flow evidence, not a natural runtime observation.
Locked catalogue snapshots show this condition by PostgreSQL 9.1.0; source behavior here is fixed at PostgreSQL 18.6.
Method: Read locked catalogue facts and definition snapshot.
Limits: First observed release is a lower bound, not precise behavioral introduction.
- src/backend/utils/errcodes.txt · REL_18_6 · line 352
724edf9bde9d356724ad384a2e196edc3c9f80f7 - src/backend/parser/parse_collate.c · REL_18_6 · lines 226-232
724edf9bde9d356724ad384a2e196edc3c9f80f7 - src/backend/parser/parse_collate.c · REL_18_6 · lines 853-858
724edf9bde9d356724ad384a2e196edc3c9f80f7 - src/backend/parser/parse_cte.c · REL_18_6 · lines 394-401
724edf9bde9d356724ad384a2e196edc3c9f80f7 - src/backend/commands/tablecmds.c · REL_18_6 · lines 3297-3303
724edf9bde9d356724ad384a2e196edc3c9f80f7 - src/backend/commands/tablecmds.c · REL_18_6 · lines 3463-3469
724edf9bde9d356724ad384a2e196edc3c9f80f7 - src/backend/commands/tablecmds.c · REL_18_6 · lines 7292-7298
724edf9bde9d356724ad384a2e196edc3c9f80f7 - src/backend/commands/tablecmds.c · REL_18_6 · lines 10474-10483
724edf9bde9d356724ad384a2e196edc3c9f80f7 - src/backend/parser/parse_collate.c · REL_18_6 · lines 208-234 and 804-835
724edf9bde9d356724ad384a2e196edc3c9f80f7 raw/calls/REL_18_6.jsonl· ·
Message templates
ERROR · message.variant-1
Primary
collation mismatch between implicit collations "%s" and "%s"
Hint
You can choose the collation by applying the COLLATE clause to one or both expressions.
Primary
You can choose the collation by applying the COLLATE clause to one or both expressions.
Placeholders remain dynamic source fields; no concrete runtime value is claimed.
ERROR · message.variant-2
Primary
collation mismatch between explicit collations "%s" and "%s"
Placeholders remain dynamic source fields; no concrete runtime value is claimed.
ERROR · message.variant-3
Primary
recursive query "%s" column %d has collation "%s" in non-recursive term but collation "%s" overall
Hint
Use the COLLATE clause to set the collation of the non-recursive term.
Primary
Use the COLLATE clause to set the collation of the non-recursive term.
Placeholders remain dynamic source fields; no concrete runtime value is claimed.
ERROR · message.variant-4
Primary
column "%s" has a collation conflict
Detail
"%s" versus "%s"
Primary
"%s" versus "%s"
Placeholders remain dynamic source fields; no concrete runtime value is claimed.
ERROR · message.variant-5
Primary
inherited column "%s" has a collation conflict
Detail
"%s" versus "%s"
Primary
"%s" versus "%s"
Placeholders remain dynamic source fields; no concrete runtime value is claimed.
ERROR · message.variant-6
Primary
child table "%s" has different collation for column "%s"
Detail
"%s" versus "%s"
Primary
"%s" versus "%s"
Placeholders remain dynamic source fields; no concrete runtime value is claimed.
ERROR · message.variant-7
Primary
foreign key constraint "%s" cannot be implemented
Detail
Key columns "%s" of the referencing table and "%s" of the referenced table have incompatible collations: "%s" and "%s". If either collation is nondeterministic, then both collations have to be the same.
Primary
Key columns "%s" of the referencing table and "%s" of the referenced table have incompatible collations: "%s" and "%s". If either collation is nondeterministic, then both collations have to be the same.
Placeholders remain dynamic source fields; no concrete runtime value is claimed.
Reproduction & repair cases
No reproduction case is attached to this condition.
Recorded runtime evidence
No runtime observation is attached to this entry.
Version history 1
- PG 9.0 → 9.1added
Definition snapshot: english-manuals:2b83f0787359b42e6bcc17e762d… · English manual source