Re: contain_nonstrict_functions_walker() fails to consider JsonExpr and CoerceToDomain

From: Tomas Vondra <tomas(at)vondra(dot)me>
To: Kirill Reshke <reshkekirill(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: contain_nonstrict_functions_walker() fails to consider JsonExpr and CoerceToDomain
Date: 2026-11-16 18:01:26
Message-ID: 133e0da5-b5f8-4575-a316-eaa790604457@vondra.me
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 11/16/26 18:30, Kirill Reshke wrote:
> On Mon, 16 Nov 2026 at 18:39, Tomas Vondra <tomas(at)vondra(dot)me> wrote:
>>
>> Hi,
>>
>
> Hi!
> I quickly looked up, JSON bugs are already reported here
> https://commitfest.postgresql.org/patch/7186/. Did you review this
> thread? Should we continue your fix instead?
> The CoerceToDomain part looks novel - no previous report.
> I didn't check your patchset details closely.
>

Hmm, I didn't notice that thread before :-( Sorry.

I've tried swapping the v4 fix from that thread for my fix, and
re-running the tests. And it triggered two differences:

1) prevented inlining in two queries:

Values Scan on "*VALUES*"
- Output: JSON_VALUE("*VALUES*".column1, '$."a"' PASSING 1 AS p
RETURNING integer DEFAULT 0 ON EMPTY DEFAULT '-1'::integer ON ERROR),
JSON_VALUE('{"a": 1}'::jsonb, "*VALUES*".column2 RETURNING integer
DEFAULT 0 ON EMPTY DEFAULT '-1'::integer ON ERROR)
+ Output: sqljson_strict_context("*VALUES*".column1),
sqljson_strict_path("*VALUES*".column2)
(2 rows)

2) failed with a couple cases that return a not-NULL domain

+ERROR: could not coerce ON ERROR expression (NULL) to the RETURNING type
+DETAIL: domain queryfuncs_int_notnull does not allow null values

I'm not sure either of these is a problem the v4 patch needs to solve. I
like that it's simpler, because if does not need to descend into the
expressions. It a more conservative fix, but maybe that's a good thing.

The (2) happens because it does not check if the domain used in the
RETURNING clause is null-rejecting. But it also interacts with the
on_error behavior, so not sure we can allow that.

regards

--
Tomas Vondra

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Manu 2026-11-16 18:47:09 Re: Do we need an index on pg_constraint.confrelid?
Previous Message Stepan Neretin 2026-11-16 17:58:12 FATAL: could not send end-of-streaming message to primary: no COPY in progress