collation of DEFAULT expression conflicts with RETURNING clause

SQLSTATE 42P21 condition collation_mismatch class 42 — Syntax Error or Access Rule Violation severity ERROR
Reproduced & verified on PostgreSQL 14.23, 15.18, 16.14, 17.10 and 18.4 — identical message on every version.
Last reviewed 8 Jun 2026 · Reproduced live with the SQL on this page.

Symptoms

A statement failed with SQLSTATE 42P21 (collation_mismatch), reported at severity ERROR. This is a Syntax Error or Access Rule Violation condition: PostgreSQL emits the message collation of DEFAULT expression conflicts with RETURNING clause.

What the server log shows

ERROR:  collation of DEFAULT expression conflicts with RETURNING clause
DETAIL:  "…" versus "…"

Why PostgreSQL raises this

Class 42 (Syntax Error or Access Rule Violation) is raised at parse/analysis time when a statement is malformed, references an object or column that cannot be resolved, or the role lacks privilege for the action.

As described in PostgreSQL’s Section 4.1 Lexical Structure and Appendix A (PostgreSQL Error Codes), SQLSTATE 42P21 carries the condition name collation_mismatch in class Syntax Error or Access Rule Violation. (Paraphrased — see the linked reference for the exact wording.)

Common causes

How to fix it

  1. Read the caret (^) in the log — it points at the offending token.
  2. Schema-qualify names or fix search_path; confirm the object exists.
  3. Quote mixed-case identifiers exactly as created.
  4. Grant the required privilege or connect as a role that has it.

Version applicability

This message text is present in PostgreSQL 17, 18, 19. It was introduced around PostgreSQL 17; earlier releases do not emit this exact text.

Related & next steps

Reference: PostgreSQL Section 4.1 Lexical Structure.