pgsql: Enforce RETURNING typmod for empty-set JSON_ARRAY(query) - Mailing list pgsql-committers

From Richard Guo
Subject pgsql: Enforce RETURNING typmod for empty-set JSON_ARRAY(query)
Date
Msg-id E1wLGVP-000pa6-2B@gemulon.postgresql.org
Whole thread
List pgsql-committers
Enforce RETURNING typmod for empty-set JSON_ARRAY(query)

Commit 8d829f5a0 introduced a COALESCE wrapper around the
JSON_ARRAYAGG subquery so that JSON_ARRAY(query) returns '[]' rather
than NULL when the subquery yields no rows, per the SQL/JSON standard.

The empty-array Const used as the COALESCE fallback was, however,
built with typmod -1 and the type input function was likewise invoked
with typmod -1.  As a result, any length restriction from the
RETURNING clause was silently bypassed on the empty-set path, while
the non-empty path enforced it via the JSON_ARRAYAGG coercion.

Build the empty-array Const using the typmod of the COALESCE's
non-empty argument, and pass that typmod to OidInputFunctionCall as
well so the value is length-checked at parse time.  This makes the
empty-set and non-empty-set paths behave consistently.

Reported-by: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Author: Richard Guo <guofenglinux@gmail.com>
Discussion: https://postgr.es/m/CAJTYsWXPYqa58YXrU+SQMVonsAhjLS46HNUMU=wO5zm9MgY3_g@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/9d124a14b3d4803afee5efc4f794dfb72016cb88

Modified Files
--------------
src/backend/parser/parse_expr.c       | 12 ++++++++----
src/test/regress/expected/sqljson.out | 19 +++++++++++++++++++
src/test/regress/sql/sqljson.sql      |  8 ++++++++
3 files changed, 35 insertions(+), 4 deletions(-)


pgsql-committers by date:

Previous
From: Amit Kapila
Date:
Subject: pgsql: Use schema-qualified names in EXCEPT clause error messages.
Next
From: John Naylor
Date:
Subject: pgsql: Fix universal builds on MacOS