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

Commit717e8a1

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 parent5e6e97f commit717e8a1

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
@@ -3764,7 +3764,7 @@ transformJsonArrayQueryConstructor(ParseState *pstate,
37643764
/* Transform query only for counting target list entries. */
37653765
qpstate=make_parsestate(pstate);
37663766

3767-
query=transformStmt(qpstate,ctor->query);
3767+
query=transformStmt(qpstate,copyObject(ctor->query));
37683768

37693769
if (count_nonjunk_tlist_entries(query->targetList)!=1)
37703770
ereport(ERROR,

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

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

750+
SELECT JSON_ARRAY(WITH x AS (SELECT 1) VALUES (TRUE));
751+
json_array
752+
------------
753+
[true]
754+
(1 row)
755+
750756
-- Should fail
751757
SELECT JSON_ARRAY(SELECT FROM (VALUES (1)) foo(i));
752758
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