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

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: sql/json query function JsonBehavior default expression's collation may differ from returning type's collation
Date: 2025-07-14 11:39:18
Message-ID: CACJufxHVwYYSyiVQ6o+PsRX6zQ7rAFinh_fv1kCfTsT1xG4Zeg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

hi.

create domain d1 as text collate case_insensitive;
select json_value('{"a": "A"}', '$.a' returning d1 default 'C' on
empty) = 'a'; --return true
select json_value('{"a": "A"}', '$.c' returning d1 default 'A' on
empty) = 'a'; --return true

select json_value('{"a": "A"}', '$.c' returning d1 default 'A' collate
"C" on empty) = 'a';
currently the above query will produce an error:
ERROR: unrecognized node type: 31
this error message needs to be fixed.

however, if no error is raised, should the query return true or false?
if not error out, It also means that the collation of the json_value expression
is determined at runtime, which makes it unsuitable for use in index creation or
check constraints.

overall, raising an error if the collation of the
JsonBehavior DEFAULT clause differs from that of the RETURNING clause
is the best option.

what do you think?

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2025-07-14 12:56:56 Re: Changing shared_buffers without restart
Previous Message Fujii Masao 2025-07-14 11:33:36 Re: Requested WAL segment xxx has already been removed