Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite33f233

Browse files
committed
Avoid double transformation of json_array()'s subquery.
transformJsonArrayQueryConstructor() applied transformStmt() tothe same subquery tree twice. While this causes no issue in manycases, there are some where it causes a coredump, thanks to theparser's habit of scribbling on its input.Fix by making a copy before the first transformation (compare0f43083). This is quite brute-force, but then so is thewhole business of transforming the input twice. Per discussionin the bug thread, this implementation of json_array() parsingshould be replaced completely. But that will take some workand will surely not be back-patchable, so for the moment let'stake the easy way out.Oversight in7081ac4. Back-patch to v16 where that came in.Bug: #18877Reported-by: Yu Liang <luy70@psu.edu>Author: Tom Lane <tgl@sss.pgh.pa.us>Discussion:https://postgr.es/m/18877-c3c3ad75845833bb@postgresql.orgBackpatch-through: 16
1 parent5db3bf7 commite33f233

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

‎src/backend/parser/parse_expr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3772,7 +3772,7 @@ transformJsonArrayQueryConstructor(ParseState *pstate,
37723772
/* Transform query only for counting target list entries. */
37733773
qpstate=make_parsestate(pstate);
37743774

3775-
query=transformStmt(qpstate,ctor->query);
3775+
query=transformStmt(qpstate,copyObject(ctor->query));
37763776

37773777
if (count_nonjunk_tlist_entries(query->targetList)!=1)
37783778
ereport(ERROR,

‎src/test/regress/expected/sqljson.out

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,12 @@ SELECT JSON_ARRAY(SELECT i FROM (VALUES (3), (1), (NULL), (2)) foo(i) ORDER BY i
751751
[1, 2, 3]
752752
(1 row)
753753

754+
SELECT JSON_ARRAY(WITH x AS (SELECT 1) VALUES (TRUE));
755+
json_array
756+
------------
757+
[true]
758+
(1 row)
759+
754760
-- Should fail
755761
SELECT JSON_ARRAY(SELECT FROM (VALUES (1)) foo(i));
756762
ERROR: subquery must return only one column

‎src/test/regress/sql/sqljson.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ SELECT JSON_ARRAY(SELECT i FROM (VALUES (NULL::int[]), ('{1,2}'), (NULL), (NULL)
199199
--SELECT JSON_ARRAY(SELECT i FROM (VALUES (NULL::int[]), ('{1,2}'), (NULL), (NULL), ('{3,4}'), (NULL)) foo(i) NULL ON NULL);
200200
--SELECT JSON_ARRAY(SELECT i FROM (VALUES (NULL::int[]), ('{1,2}'), (NULL), (NULL), ('{3,4}'), (NULL)) foo(i) NULL ON NULL RETURNING jsonb);
201201
SELECT JSON_ARRAY(SELECT iFROM (VALUES (3), (1), (NULL), (2)) foo(i)ORDER BY i);
202+
SELECT JSON_ARRAY(WITH xAS (SELECT1)VALUES (TRUE));
203+
202204
-- Should fail
203205
SELECT JSON_ARRAY(SELECTFROM (VALUES (1)) foo(i));
204206
SELECT JSON_ARRAY(SELECT i, iFROM (VALUES (1)) foo(i));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp