=== Applying patches on top of PostgreSQL commit ID d451ca6917e35ce5aeee032462b3cd783d7a706e === /etc/rc.d/jail: WARNING: Per-jail configuration via jail_* variables is obsolete. Please consider migrating to /etc/jail.conf. Sun Jul 19 21:52:29 UTC 2026 On branch cf/6975 nothing to commit, working tree clean === using 'git am' to apply patch ./v1-0001-Refactor-json_categorize_type-to-populate-an-Fmgr.patch === Applying: Refactor json_categorize_type() to populate an FmgrInfo * Using index info to reconstruct a base tree... M src/backend/executor/execExprInterp.c M src/backend/utils/adt/json.c M src/backend/utils/adt/jsonb.c M src/test/regress/expected/sqljson.out M src/test/regress/sql/sqljson.sql Falling back to patching base and 3-way merge... Auto-merging src/test/regress/sql/sqljson.sql CONFLICT (content): Merge conflict in src/test/regress/sql/sqljson.sql Auto-merging src/test/regress/expected/sqljson.out CONFLICT (content): Merge conflict in src/test/regress/expected/sqljson.out Auto-merging src/backend/utils/adt/jsonb.c Auto-merging src/backend/utils/adt/json.c Auto-merging src/backend/executor/execExprInterp.c error: Failed to merge in the changes. hint: Use 'git am --show-current-patch=diff' to see the failed patch Patch failed at 0001 Refactor json_categorize_type() to populate an FmgrInfo * When you have resolved this problem, run "git am --continue". If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort". === using patch(1) to apply patch ./v1-0001-Refactor-json_categorize_type-to-populate-an-Fmgr.patch === patching file src/backend/executor/execExpr.c patching file src/backend/executor/execExprInterp.c patching file src/backend/utils/adt/json.c patching file src/backend/utils/adt/jsonb.c patching file src/backend/utils/adt/jsonfuncs.c patching file src/include/executor/execExpr.h patching file src/include/utils/jsonfuncs.h patching file src/test/regress/expected/sqljson.out Hunk #1 FAILED at 1757. 1 out of 1 hunk FAILED -- saving rejects to file src/test/regress/expected/sqljson.out.rej patching file src/test/regress/sql/sqljson.sql Hunk #1 FAILED at 706. 1 out of 1 hunk FAILED -- saving rejects to file src/test/regress/sql/sqljson.sql.rej Unstaged changes after reset: M src/backend/executor/execExpr.c M src/backend/executor/execExprInterp.c M src/backend/utils/adt/json.c M src/backend/utils/adt/jsonb.c M src/backend/utils/adt/jsonfuncs.c M src/include/executor/execExpr.h M src/include/utils/jsonfuncs.h Removing src/test/regress/expected/sqljson.out.rej Removing src/test/regress/sql/sqljson.sql.rej === using 'git apply' to apply patch ./v1-0001-Refactor-json_categorize_type-to-populate-an-Fmgr.patch === Applied patch to 'src/backend/executor/execExpr.c' cleanly. Applied patch to 'src/backend/executor/execExprInterp.c' cleanly. Applied patch to 'src/backend/utils/adt/json.c' cleanly. Applied patch to 'src/backend/utils/adt/jsonb.c' cleanly. Applied patch to 'src/backend/utils/adt/jsonfuncs.c' cleanly. Applied patch to 'src/include/executor/execExpr.h' cleanly. Applied patch to 'src/include/utils/jsonfuncs.h' cleanly. Applied patch to 'src/test/regress/expected/sqljson.out' with conflicts. Applied patch to 'src/test/regress/sql/sqljson.sql' with conflicts. U src/test/regress/expected/sqljson.out U src/test/regress/sql/sqljson.sql diff --cc src/test/regress/expected/sqljson.out index 091a0b98574,fedbeca7a21..00000000000 --- a/src/test/regress/expected/sqljson.out +++ b/src/test/regress/expected/sqljson.out @@@ -1757,104 -1757,7 +1757,111 @@@ SELECT JSON_OBJECT('a': JSON_OBJECTAGG( (1 row) DROP FUNCTION volatile_one, stable_one; ++<<<<<<< ours +-- Test deparsing of JSON aggregates that are computed below a WindowAgg +-- node. +EXPLAIN (VERBOSE, COSTS OFF) +SELECT i % 2 AS g, + JSON_ARRAYAGG(i ORDER BY i RETURNING jsonb) AS ja, + JSON_ARRAYAGG(i ORDER BY i RETURNING text) AS ja_text, + JSON_ARRAYAGG(i ORDER BY i NULL ON NULL RETURNING jsonb) AS ja_null, + JSON_OBJECTAGG(i: i ABSENT ON NULL RETURNING jsonb) AS jo_absent, + JSON_OBJECTAGG(i: i WITH UNIQUE RETURNING jsonb) AS jo_unique, + row_number() OVER (ORDER BY i % 2) AS rn +FROM generate_series(1, 3) i +GROUP BY i % 2; + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ + WindowAgg + Output: ((i % 2)), JSON_ARRAYAGG(i ORDER BY i RETURNING jsonb), JSON_ARRAYAGG(i ORDER BY i RETURNING text), JSON_ARRAYAGG(i ORDER BY i NULL ON NULL RETURNING jsonb), JSON_OBJECTAGG(i : i ABSENT ON NULL RETURNING jsonb), JSON_OBJECTAGG(i : i WITH UNIQUE KEYS RETURNING jsonb), row_number() OVER w1 + Window: w1 AS (ORDER BY ((i.i % 2)) ROWS UNBOUNDED PRECEDING) + -> GroupAggregate + Output: ((i % 2)), jsonb_agg_strict(i ORDER BY i), json_agg_strict(i ORDER BY i), jsonb_agg(i ORDER BY i), jsonb_object_agg_strict(i, i), jsonb_object_agg_unique(i, i) + Group Key: ((i.i % 2)) + -> Sort + Output: ((i % 2)), i + Sort Key: ((i.i % 2)), i.i + -> Function Scan on pg_catalog.generate_series i + Output: (i % 2), i + Function Call: generate_series(1, 3) +(12 rows) + +SELECT i % 2 AS g, + JSON_ARRAYAGG(i ORDER BY i RETURNING jsonb) AS ja, + JSON_ARRAYAGG(i ORDER BY i RETURNING text) AS ja_text, + JSON_ARRAYAGG(i ORDER BY i NULL ON NULL RETURNING jsonb) AS ja_null, + JSON_OBJECTAGG(i: i ABSENT ON NULL RETURNING jsonb) AS jo_absent, + JSON_OBJECTAGG(i: i WITH UNIQUE RETURNING jsonb) AS jo_unique, + row_number() OVER (ORDER BY i % 2) AS rn +FROM generate_series(1, 3) i +GROUP BY i % 2; + g | ja | ja_text | ja_null | jo_absent | jo_unique | rn +---+--------+---------+---------+------------------+------------------+---- + 0 | [2] | [2] | [2] | {"2": 2} | {"2": 2} | 1 + 1 | [1, 3] | [1, 3] | [1, 3] | {"1": 1, "3": 3} | {"1": 1, "3": 3} | 2 +(2 rows) + +-- The same, but with the JSON aggregate used as a window function that is +-- computed below another WindowAgg node. +EXPLAIN (VERBOSE, COSTS OFF) +SELECT JSON_ARRAYAGG(i NULL ON NULL RETURNING jsonb) OVER (ORDER BY i DESC) AS ja, + row_number() OVER (ORDER BY i) AS rn +FROM generate_series(1, 3) i; + QUERY PLAN +------------------------------------------------------------------------------------------ + WindowAgg + Output: JSON_ARRAYAGG(i NULL ON NULL RETURNING jsonb) OVER w1, row_number() OVER w2, i + Window: w2 AS (ORDER BY i.i ROWS UNBOUNDED PRECEDING) + -> Sort + Output: i, (jsonb_agg(i) OVER w1) + Sort Key: i.i + -> WindowAgg + Output: i, jsonb_agg(i) OVER w1 + Window: w1 AS (ORDER BY i.i) + -> Sort + Output: i + Sort Key: i.i DESC + -> Function Scan on pg_catalog.generate_series i + Output: i + Function Call: generate_series(1, 3) +(15 rows) + +SELECT JSON_ARRAYAGG(i NULL ON NULL RETURNING jsonb) OVER (ORDER BY i DESC) AS ja, + row_number() OVER (ORDER BY i) AS rn +FROM generate_series(1, 3) i; + ja | rn +-----------+---- + [3, 2, 1] | 1 + [3, 2] | 2 + [3] | 3 +(3 rows) + +-- The same, but with the expression containing the JSON aggregate postponed +-- to above the final sort due to being volatile. +EXPLAIN (VERBOSE, COSTS OFF) +SELECT i % 2 AS g, + JSON_ARRAYAGG(i RETURNING text) || random()::text AS ja +FROM generate_series(1, 3) i +GROUP BY i % 2 +ORDER BY count(*); + QUERY PLAN +---------------------------------------------------------------------------------------- + Result + Output: ((i % 2)), (JSON_ARRAYAGG(i RETURNING text) || (random())::text), (count(*)) + -> Sort + Output: ((i % 2)), (count(*)), (json_agg_strict(i)) + Sort Key: (count(*)) + -> HashAggregate + Output: ((i % 2)), count(*), json_agg_strict(i) + Group Key: (i.i % 2) + -> Function Scan on pg_catalog.generate_series i + Output: (i % 2), i + Function Call: generate_series(1, 3) +(11 rows) + ++======= + -- JSON_ARRAY(ROW(...)) is not immutable, so it should be impossible to + -- create a generated column. + -- XXX: Currently, this is erroneously allowed. + CREATE TABLE json_array_of_row (a int, j json GENERATED ALWAYS AS (JSON_ARRAY(ROW(a))) STORED); ++>>>>>>> theirs diff --cc src/test/regress/sql/sqljson.sql index 2550da15c45,77910137573..00000000000 --- a/src/test/regress/sql/sqljson.sql +++ b/src/test/regress/sql/sqljson.sql @@@ -707,43 -707,7 +707,50 @@@ EXPLAIN (VERBOSE, COSTS OFF) SELECT JSO SELECT JSON_OBJECT('a': JSON_OBJECTAGG('b': 1 RETURNING text) FORMAT JSON); DROP FUNCTION volatile_one, stable_one; ++<<<<<<< ours +-- Test deparsing of JSON aggregates that are computed below a WindowAgg +-- node. +EXPLAIN (VERBOSE, COSTS OFF) +SELECT i % 2 AS g, + JSON_ARRAYAGG(i ORDER BY i RETURNING jsonb) AS ja, + JSON_ARRAYAGG(i ORDER BY i RETURNING text) AS ja_text, + JSON_ARRAYAGG(i ORDER BY i NULL ON NULL RETURNING jsonb) AS ja_null, + JSON_OBJECTAGG(i: i ABSENT ON NULL RETURNING jsonb) AS jo_absent, + JSON_OBJECTAGG(i: i WITH UNIQUE RETURNING jsonb) AS jo_unique, + row_number() OVER (ORDER BY i % 2) AS rn +FROM generate_series(1, 3) i +GROUP BY i % 2; +SELECT i % 2 AS g, + JSON_ARRAYAGG(i ORDER BY i RETURNING jsonb) AS ja, + JSON_ARRAYAGG(i ORDER BY i RETURNING text) AS ja_text, + JSON_ARRAYAGG(i ORDER BY i NULL ON NULL RETURNING jsonb) AS ja_null, + JSON_OBJECTAGG(i: i ABSENT ON NULL RETURNING jsonb) AS jo_absent, + JSON_OBJECTAGG(i: i WITH UNIQUE RETURNING jsonb) AS jo_unique, + row_number() OVER (ORDER BY i % 2) AS rn +FROM generate_series(1, 3) i +GROUP BY i % 2; + +-- The same, but with the JSON aggregate used as a window function that is +-- computed below another WindowAgg node. +EXPLAIN (VERBOSE, COSTS OFF) +SELECT JSON_ARRAYAGG(i NULL ON NULL RETURNING jsonb) OVER (ORDER BY i DESC) AS ja, + row_number() OVER (ORDER BY i) AS rn +FROM generate_series(1, 3) i; +SELECT JSON_ARRAYAGG(i NULL ON NULL RETURNING jsonb) OVER (ORDER BY i DESC) AS ja, + row_number() OVER (ORDER BY i) AS rn +FROM generate_series(1, 3) i; + +-- The same, but with the expression containing the JSON aggregate postponed +-- to above the final sort due to being volatile. +EXPLAIN (VERBOSE, COSTS OFF) +SELECT i % 2 AS g, + JSON_ARRAYAGG(i RETURNING text) || random()::text AS ja +FROM generate_series(1, 3) i +GROUP BY i % 2 +ORDER BY count(*); ++======= + -- JSON_ARRAY(ROW(...)) is not immutable, so it should be impossible to + -- create a generated column. + -- XXX: Currently, this is erroneously allowed. + CREATE TABLE json_array_of_row (a int, j json GENERATED ALWAYS AS (JSON_ARRAY(ROW(a))) STORED); ++>>>>>>> theirs