Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wF2FF-004gMh-0J for pgsql-bugs@arkaria.postgresql.org; Tue, 21 Apr 2026 03:57:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wF2FE-005k2H-1K for pgsql-bugs@arkaria.postgresql.org; Tue, 21 Apr 2026 03:57:52 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wF2Ew-005gxv-1J for pgsql-bugs@lists.postgresql.org; Tue, 21 Apr 2026 03:57:34 +0000 Received: from mail-oo1-xc35.google.com ([2607:f8b0:4864:20::c35]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wF2Eu-00000002EgV-1TVz for pgsql-bugs@lists.postgresql.org; Tue, 21 Apr 2026 03:57:34 +0000 Received: by mail-oo1-xc35.google.com with SMTP id 006d021491bc7-69485d0e4beso587315eaf.3 for ; Mon, 20 Apr 2026 20:57:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1776743850; cv=none; d=google.com; s=arc-20240605; b=ZA9FrvGM8HPPsDEpKc0+rKLJBeKy3HsI9G/WCVFkzLVJ0SvBwlcnrgF2BV661UjuIG ySLsa27uZhME5D5n3dbv0cjzl0ShONpXdhkxN2xIp16taa3NpOWBCcauA144A8M5ANVR 9flXLN6n+B+gA84DIcP0lERcgDeHkhYKGmR2/2G7NYMYLiCi9TSI1X14R1xt5Imtodjn 5NcR92tPEBqJW0UQQ1A813Q00zeFOuDNDSqkKM7qKxr4YcjbQhzIGvhf7O13zpkbV0Wv Tfdf5lIFPbBdHk3JqYlGKKt+ZMazVi8lI7u2KKR7o2Dfwzlu+GT32wVoy+YE04vLFkOH w3yw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=FWXeVZTynb4qLDFo8LpORjRyg6C00VMJuccpJWSqMfE=; fh=c/KykCOi5F1iz3Wsn1gce8dhnUpJJPiqAWhiAA3R9Y8=; b=a9SRcpCVeScXeI7tW9SxLqe7dQnHBw0Us4jg84HZoN6Bv9LFtEBBqphCBPtjGgvJ1e pxLUrmxk3B8kN+NvA1Lp2IZbMZN1DLTkWMv50wyS5JvKkR0OpFA1LxrIzq16i5nPhkR5 XN+Sxg9N0H5QPVil6lbhBAtxRIWVtCnnUVo1pXswI0wwqHlRCjp9SY/OxzATKf/eD0GN 3pStkfTmaXWNprd+B4ujuoZDorkPYHMtHh+UzuEA2JTA1ZUCt9WO6f/Wcj+Lw+DRYc4z WDaHsSu2FHnbX73nIgYN9m5ZJAZngKYrjB+HsGX1CgwjostEERWg4T0y1mBOHTexLWR0 vWGQ==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776743850; x=1777348650; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=FWXeVZTynb4qLDFo8LpORjRyg6C00VMJuccpJWSqMfE=; b=nF3gkSmVwwPB+pK3w09/G4mxjJnZhvWxezdrS5d+PALkrXywWlSvy4VSOmNDaS1lFi BPJY3zWmAKYzRZ+R4iH2KUWUX4303WcB538mr8t09drnU2ABAZsKgJMMjPIXwSvYOkOv bRQNv5fUzduJrl3vQTYzwWvqWs1H6I1nTqJI98rdXoqZzdEccwHJtdHdCHAep8vdIqtk UWXXnJwVjxqHCkq9qY9OTuP87qx53z9XeGXgT5k1WdbnMtLuXOer0w0qtkKIzehuDg4L SHtEAzXkjI+8i3OPHE2UKuV1lElMheztIB+9qQbSeiMafBg4c3aeVul37w6wgxl0Txcm tHQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776743850; x=1777348650; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=FWXeVZTynb4qLDFo8LpORjRyg6C00VMJuccpJWSqMfE=; b=lZcciwq8T7ikIQXek2dHgllEt7/5UVXn8fUjZRf5NHYOSRyfWRO2Gx7msybXo88ESs DhpF84nExxeBjMfEm2IF+MFC7dfqxmD0C3klDoZokWa+KOtl0H96t8b6NHhLvaNgcnWP +PfdAwvIanHgUsurrGSPMUFHNp99XfRaoU3uKb8xJF/lXH3rA64sklAZPMvltHwAcOWm zdAjydSggVAXsjpStPNophsCfpc/eCe4iQ804Goq0RnMFXMSBAROjI5VDQVvJIsXBcCF d7m12Vo5PHARKne2S2hGtAqF4b4XaGAD/w06haZ5DYpnui6vKKuMbWDRgcwADvYajj9c wu2w== X-Forwarded-Encrypted: i=1; AFNElJ/2UrSuGw+EOSbryJDGz3rCT36WvnqHHvmV8NwGxQvxPCxXyf9VF+0Ijq2KZYmzJ2rU38xAboBGousr@lists.postgresql.org X-Gm-Message-State: AOJu0YxKQA/yuB5KH/C5icMSfOgUY+C0lYd7Xi8MjO78Sb4WoVEEwv3K B4OhXfMooiM57XGCoIz77hz9rAvjks3gVCTxloyx9KcoxJAq+3nXmdAvUY0LIMlidQ4SqhQAnJp W4d2eLARvlF7NxPcmLR/ae641+E2lTks= X-Gm-Gg: AeBDiesf8Ox2dxrxHJ1PacN1IIaSE+nAC9UxtjU3b41Ep5WJ6ykcxQpYaQVkmX6m9UR 0yoWjBMSgkWKbGPqukVSfQ8B+iuZk+kgodcdJpzZDohcuM2KkogvfYnI/jPZd3H9jQvvD8svc8l 3ac9l+n418r+ua6f3N0npZPfJPZfe2KCPpXCB/zlcmkcYDUvpRmdfS0nwtQRKzlFkQyFXJHDMs0 4SVficsB6CgNzqg0KxeBUSGi2UdIUoYclZ4m9Pkp5mTtKImFR4JMhm88MauxG8/qR0BuXYI9/eF j56a8QuAQVAwqNGWElUo096FCYB1uUtZnYl2bH+r6oAWTQDVY+I3Yv31Qwbia0Sx8nlltunTNxA = X-Received: by 2002:a05:6820:1c84:b0:694:90ff:c769 with SMTP id 006d021491bc7-69490ffc901mr2262164eaf.3.1776743850499; Mon, 20 Apr 2026 20:57:30 -0700 (PDT) MIME-Version: 1.0 References: <19418-591ba1f29862ef5b@postgresql.org> <2abdb464-27f5-4759-bb0b-f09ab5b5ceab@postgresfriends.org> <501040.1772433449@sss.pgh.pa.us> In-Reply-To: From: Amit Langote Date: Tue, 21 Apr 2026 12:57:12 +0900 X-Gm-Features: AQROBzAZa3mETfHPE8Htkt_8kXx5bd4qjg7MMsPWohfjB8tBwxqpvBxiGWCK8O0 Message-ID: Subject: Re: BUG #19418: SQL/JSON JSON_VALUE() does not conform to ISO/IEC 9075-2:2023(E) 6.34 To: Richard Guo Cc: Tom Lane , Vik Fearing , lukas.eder@gmail.com, pgsql-bugs@lists.postgresql.org, =?UTF-8?Q?=C3=81lvaro_Herrera?= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, Apr 21, 2026 at 9:57=E2=80=AFAM Richard Guo wrote: > On Mon, Apr 20, 2026 at 6:05=E2=80=AFPM Amit Langote wrote: > > Agreed that v4 is the better direction. > > Thanks for review! > > > The comment on orig_query could say "not walked" a bit more helpfully, = e.g. > > > > Node *orig_query; /* for deparse only; not walked (func is) *= / > > Sounds good. > > > I also noticed that the comment for 'func' is incomplete as it is and > > this change warrants an update. Maybe a bit long, but how about: > > > > Expr *func; /* expression producing the result: > > * Aggref/WindowFunc for *AGG, > > * CoalesceExpr for ARRAY_QUERY, > > * json[b]_xxx() call for remaining typ= es */ > > It seems that func is NULL for "remaining types". How about we go > with: > > Expr *func; /* executable expression: > * Aggref/WindowFunc for *AGG, > * CoalesceExpr for ARRAY_QUERY, > * NULL for other types (executor calls > * underlying json[b]_xxx() functions) */ Right. > (maybe we should place the multi-line comment above the field.) Makes sense. Perhaps we should also move the description of individual fields, where needed, into the comment above the struct definition like it is done for the nearby JsonValueExpr. Like this: /* * JsonConstructorExpr - * wrapper over FuncExpr/Aggref/WindowFunc/CoalesceExpr for SQL/JSON * constructors * * func is the executable expression: * - Aggref/WindowFunc for JSON_OBJECTAGG/JSON_ARRAYAGG, * - CoalesceExpr for JSON_ARRAY(query), * - NULL for other types (the executor calls the underlying json[b]_xxx() * function directly). * * orig_query holds the user's original subquery for JSON_ARRAY(query), * used only by ruleutils.c for deparsing; it is not walked because func * is authoritative for all other purposes. */ typedef struct JsonConstructorExpr { Expr xpr; JsonConstructorType type; /* constructor type */ List *args; Expr *func; /* executable expression or NULL */ Node *orig_query; /* original subquery for deparsing */ Expr *coercion; /* coercion to RETURNING type */ JsonReturning *returning; /* RETURNING clause */ bool absent_on_null; /* ABSENT ON NULL? */ bool unique; /* WITH UNIQUE KEYS? (JSON_OBJECT[AGG] only= ) */ ParseLoc location; } JsonConstructorExpr; --=20 Thanks, Amit Langote