Hi Amit, Tomas,

On Fri, Nov 20, 2026 Amit Langote wrote:
> Its JsonBehavior case returned without letting the walker look at the
> behavior's expression any further, which misses a DEFAULT expression
> containing a subquery.

Thanks, v6 has the same bug; this returns 1 instead of NULL:

    SELECT v FROM (VALUES (1)) a
    LEFT JOIN (SELECT JSON_VALUE(jsonb '{}', '$.a' RETURNING int
                                 DEFAULT num_nulls((SELECT y)) ON EMPTY) v
               FROM (VALUES (1), (2)) b(y)) ss ON false;

Attached v7:

0001: the JsonBehavior case now falls through as in your v2, with the
query above as a test.  No reference to use_json_coercion, so the same
patch applies to master through 17 and can go in before the flag
removal.  I also consolidated the tests, which had grown over the
versions.

0002: the same JsonExpr / JsonBehavior handling in
full_join_expr_nonstrict_walker(), to keep it in sync as Tomas
suggested.  Without it, an operand like
JSON_VALUE(jsonb '0', '$' PASSING b.x AS p RETURNING int) counts as
null-preserving, and FULL JOIN ... WHERE COALESCE(a.x, <that>) = 0
loses unmatched rows; see the new tests in join.sql.  It only needs to
go back to 17. 0002 covers only JsonExpr; CoerceToDomain is still missing
in both walkers and is left to your thread.

Regards,
Zhenglong

Attachment: v7-0001-Fix-planner-s-strictness-check-for-JsonExpr.patch
Description: Binary data

Attachment: v7-0002-Handle-JsonExpr-in-FULL-JOIN-null-preservation-ch.patch
Description: Binary data

Reply via email to