Re: sql/json query function JsonBehavior default expression's collation may differ from returning type's collation

From: Amit Langote <amitlangote09(at)gmail(dot)com>
To: jian he <jian(dot)universality(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: sql/json query function JsonBehavior default expression's collation may differ from returning type's collation
Date: 2025-10-08 04:10:03
Message-ID: CA+HiwqGO0mdq6CYEipoZnP8ug34k+zSPNkJELCuBuVh47o2NwA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Oct 6, 2025 at 10:58 PM Amit Langote <amitlangote09(at)gmail(dot)com> wrote:
> (Sorry for the long delay -- I meant to get back to this a while ago.)
>
> Thanks for posting v2 of the patch. I’ve made a few follow-up changes
> (v3 attached):
>
> * Moved the regression tests from sqljson_queryfuncs.sql to
> collation.icu.utf8.sql to avoid failures on buildfarm machines without
> ICU support.
>
> * Adjusted the collation-mismatch check in transformJsonBehavior() so
> that it runs last within the DEFAULT-handling block. That keeps the
> control flow cleaner and avoids affecting existing tests that already
> fail earlier checks, preventing unnecessary regression output churn.
>
> * Did a few cosmetic edits and fixed the error code and message text.
>
> Otherwise, behavior and coverage remain the same.

After sleeping on this, I realized the right fix is not to strip
CollateExpr in transformJsonBehavior(), but to stop recursing on
JsonBehavior.expr in exprSetCollation(). With this patch, the parser
now ensures that the JsonBehavior.expr has the correct collation, so
the recursion isn’t needed. There is now an Assert in its place that
checks that JsonBehavior.expr already has the target collation.

Attached v4.

--
Thanks, Amit Langote

Attachment Content-Type Size
v4-0001-Fix-internal-error-from-CollateExpr-in-SQL-JSON-D.patch application/octet-stream 12.3 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Chao Li 2025-10-08 04:36:35 Re: Optimize LISTEN/NOTIFY
Previous Message David Rowley 2025-10-08 04:02:39 Re: Should we update the random_page_cost default value?