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.94.2) (envelope-from ) id 1tpWm4-007DRh-Dx for pgsql-hackers@arkaria.postgresql.org; Tue, 04 Mar 2025 18:13:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tpWm2-004HZA-Sm for pgsql-hackers@arkaria.postgresql.org; Tue, 04 Mar 2025 18:13:46 +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.94.2) (envelope-from ) id 1tpWm2-004HZ2-BA for pgsql-hackers@lists.postgresql.org; Tue, 04 Mar 2025 18:13:46 +0000 Received: from mail-qv1-xf35.google.com ([2607:f8b0:4864:20::f35]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tpWlx-000wh6-37 for pgsql-hackers@postgresql.org; Tue, 04 Mar 2025 18:13:45 +0000 Received: by mail-qv1-xf35.google.com with SMTP id 6a1803df08f44-6dd420f82e2so80929656d6.1 for ; Tue, 04 Mar 2025 10:13:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dunslane-net.20230601.gappssmtp.com; s=20230601; t=1741112022; x=1741716822; darn=postgresql.org; h=in-reply-to:autocrypt:content-language:from:references:cc:to :subject:user-agent:mime-version:date:message-id:from:to:cc:subject :date:message-id:reply-to; bh=tg+8vOFXOoCOHfB6k80gRqEDPsml+C4rFTnsP4+l60w=; b=Ot2YM6ODt5z/S7rRitf835dtDxxyNj4s8xhhcRGv+1FbOOuF3ehbSsl/+JloH3USMs B51CXKM7MY7ES8oYX10zBmroQCvZoWTmWmUie1IL14hbCpvcamu15zbsa43OE4lehXVu cpWdN2xe0p8notkFpGqHhDIAlkpIkXg5xkKdHzIUWnl1vF7V9f+1ytHihQgxTqRwamAg 3+6E31txkDNGu6FcLHKMspEkcXaozN739/STPnOMx0W8MiylrTy94R7L5v58BBhY5UEr 2ktPxDWx0Grilje169K6hSUp8Dqis2z6rEFpcMOOzipn/IVVHdK+nV7p/0NPdnYvDEXh Tm5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741112022; x=1741716822; h=in-reply-to:autocrypt:content-language:from:references:cc:to :subject:user-agent:mime-version:date:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=tg+8vOFXOoCOHfB6k80gRqEDPsml+C4rFTnsP4+l60w=; b=vrmcnMscCse9R6X4ialva7y+9E64dcnPCewnwNSLzr7MHIdcK18uqzaORb//FFBhMJ Eooov7DNd/Cg7bb9gqxe4MISfcWHtM933E29UaEq2OZo7qjGte5oeF5DDhf29T2lRNf5 tQEBp1CpKlFaEgO8ExL6GQRnhWglbO3xQ/RmaRMM1qEJVR4O1fofFKAVS05C9vQ7ift4 b3KPOuMpOhGNDfJ72HHTrSXUSo/kEadzo0MwdNbTC75jWdwrU+NZbCXxI1UU9TWACln+ BL6az43doatKvDApwKY6Gvyrq430UYQRKXHMyKicpkeTsAXEfgb1eFiMLkRezMrCvOZE bwOA== X-Forwarded-Encrypted: i=1; AJvYcCXEOV4RSifrVhdz1hcsgiiMkRuGuhbFQ1+p20G55R4LYdYkvv7xmDf/s5etUWbiAoRnthNRVihp8UQzZhgt@postgresql.org X-Gm-Message-State: AOJu0YzOOdsGbbYYttv5ZkqA8BWGJkOAwb5fmWCxQ9FmPEDFdTKo3LHI tUuIM2IWucGcq6pK9746cUlVPFVettDa16OrYWWVtU1LfplSVf5SLmnB/5r3p9E= X-Gm-Gg: ASbGncsVWPzGWBTLtVcgv5x3T3v7+TVnAWn/MRRBxXeVPZXcd8MP0pOD+0jFgiC3ZWB Kp4ufKGzS6UXBOwoB4wqzv1EGjpRVoIAV/6lq6/tgKLejMfM8clhIoWOKdXzvPM2OKFp4oY1NrY ipYCS5fkStlIMviGKvbQOZsWJbtRcqYf6xTBbFIEbWxtVYYEjWpXVvR41W0/BP7vhKnV6bb9o8f IdjsbmrVR6X/Zl++oYoiAgvAboOz4iXkwE2FDoJaQRflGB+HbFfmX/FERUMovAMgWtBuMho0tuI 3V/0OyeW9H/DIc7QYe/3+p/FULZUAW7v5AUmVve7+6airokuaUp6zHY= X-Google-Smtp-Source: AGHT+IFasK8d9pkVIa8k2B/OaiVW6I6Pw8T9+5eg0J1vuFFn2GRYE6YuUEyxe2YC8bxzab5hY020MQ== X-Received: by 2002:a05:6214:4118:b0:6e4:27a0:f0f7 with SMTP id 6a1803df08f44-6e8e6cdd3bfmr4337896d6.22.1741112021638; Tue, 04 Mar 2025 10:13:41 -0800 (PST) Received: from ?IPV6:2605:a601:a681:6b00::1cb? ([2605:a601:a681:6b00::1cb]) by smtp.googlemail.com with ESMTPSA id d75a77b69052e-474e817b59dsm31077261cf.22.2025.03.04.10.13.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 04 Mar 2025 10:13:40 -0800 (PST) Content-Type: multipart/alternative; boundary="------------mJjCjgQgAKQVSfqcp9bI35ec" Message-ID: <4a527da4-7fc3-4c1c-a59b-dd08e405eb38@dunslane.net> Date: Tue, 4 Mar 2025 13:13:39 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: SQL:2023 JSON simplified accessor support To: Mark Dilger , Alexandra Wang Cc: Matheus Alcantara , Peter Eisentraut , Nikita Glukhov , PostgreSQL Hackers , "David E. Wheeler" , jian he References: <21fa36b4-6d56-4556-b524-9e3955b922c8@eisentraut.org> From: Andrew Dunstan Content-Language: en-US Autocrypt: addr=andrew@dunslane.net; keydata= xsBNBE7KWFkBCAClridxur2AIc7eW2AR7izbfp3EnNefie2HbLF0izW5Ik5UjX2HBX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MWOvpP/ExJPguEfjOsO6Njy xjo3WfpD4lHMOR/Oc3/8mScEF84rF2jXbsFgelWnbPWAvXY+pD0dXOFRkagGmC/viwBDqq5b 5tk76kKmUbZxABEBAAHCwHwEGAEIACYCGwwWIQTkPlhGHfx8v0RpFaWZ+n/LWfw7gQUCZFlx 5wUJGVGAjgAKCRCZ+n/LWfw7gf+iB/4g8CPY5jihf5r/8EsoIGe2H+dpVmpPF8YGBzTIvCz/ fQoOq8AX/pE76QEuFnFZWfjw+wgBXgCVmkox2Eflkk6z4ND3pcwGZ6CfCxTQCDk/dij+2DQ4 6bmDCy/sBgcbz9mTpoLC11HLoPae6YN9nBNQRZDcEFEu54OaVOqlIdbA6m+POIBCXZdHOFc0 WoDTgxHRzC1jgQNidyd6tKqcsVJs0dzF0oKTmFFmUAqTdJO12LBuNA1rlqrR3EtpYk8B/wtS 5dIMD7Q8hwQpL+4C6GNpb6ZKnPkLi47pDOLhz2qBrqN+rqUEsT3YnExYpzj5yOBi+FlmV1Hw 49QYe1sn2ZPs In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------mJjCjgQgAKQVSfqcp9bI35ec Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 2025-03-04 Tu 10:34 AM, Mark Dilger wrote: > > > On Tue, Mar 4, 2025 at 6:05 AM Mark Dilger > wrote: > > But then I tried: > > +DO $$ > +DECLARE > +  a jsonb := '{"": 6, "NU": [{"": [[3]]}, [6], [2], "bCi"], > "aaf": [-6, -8]}'::jsonb; > +BEGIN > +  WHILE a IS NOT NULL > +  LOOP > +    RAISE NOTICE '%', a; > +    a := COALESCE(a."NU", a[2]); > +  END LOOP; > +END > +$$ LANGUAGE plpgsql; > +NOTICE:  {"": 6, "NU": [{"": [[3]]}, [6], [2], "bCi"], "aaf": > [-6, -8]} > +ERROR:  missing FROM-clause entry for table "a" > +LINE 1: a := COALESCE(a."NU", a[2]) > +                      ^ > +QUERY:  a := COALESCE(a."NU", a[2]) > +CONTEXT:  PL/pgSQL function inline_code_block line 8 at assignment > > which suggests the plpgsql parser does not recognize a."NU" as > we'd expect.  Any thoughts on this? > > > I should mention that > > +DO $$ > +DECLARE > +  a jsonb := '{"": 6, "NU": [{"": [[3]]}, [6], [2], "bCi"], "aaf": > [-6, -8]}'::jsonb; > +BEGIN > +  WHILE a IS NOT NULL > +  LOOP > +    RAISE NOTICE '%', a; > +    a := COALESCE((a)."NU", (a)[2]); > +  END LOOP; > +END > +$$ LANGUAGE plpgsql; > +NOTICE:  {"": 6, "NU": [{"": [[3]]}, [6], [2], "bCi"], "aaf": [-6, -8]} > +NOTICE:  [{"": [[3]]}, [6], [2], "bCi"] > +NOTICE:  [2] > works fine.  I guess that is good enough.  Should we add these to the > sql/jsonb.sql to document the expected behavior, both with the error > when using plain "a" and with the correct output when using "(a)"?  > The reason I mention this is that the plpgsql parser might get changed > at some point, and without a test case, we might not notice if this > breaks. > Yes, I think so. cheers andrew -- Andrew Dunstan EDB:https://www.enterprisedb.com --------------mJjCjgQgAKQVSfqcp9bI35ec Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit


On 2025-03-04 Tu 10:34 AM, Mark Dilger wrote:


On Tue, Mar 4, 2025 at 6:05 AM Mark Dilger <mark.dilger@enterprisedb.com> wrote:
But then I tried:

+DO $$
+DECLARE
+  a jsonb := '{"": 6, "NU": [{"": [[3]]}, [6], [2], "bCi"], "aaf": [-6, -8]}'::jsonb;
+BEGIN
+  WHILE a IS NOT NULL
+  LOOP
+    RAISE NOTICE '%', a;
+    a := COALESCE(a."NU", a[2]);
+  END LOOP;
+END
+$$ LANGUAGE plpgsql;
+NOTICE:  {"": 6, "NU": [{"": [[3]]}, [6], [2], "bCi"], "aaf": [-6, -8]}
+ERROR:  missing FROM-clause entry for table "a"
+LINE 1: a := COALESCE(a."NU", a[2])
+                      ^
+QUERY:  a := COALESCE(a."NU", a[2])
+CONTEXT:  PL/pgSQL function inline_code_block line 8 at assignment

which suggests the plpgsql parser does not recognize a."NU" as we'd expect.  Any thoughts on this?

I should mention that

+DO $$
+DECLARE
+  a jsonb := '{"": 6, "NU": [{"": [[3]]}, [6], [2], "bCi"], "aaf": [-6, -8]}'::jsonb;
+BEGIN
+  WHILE a IS NOT NULL
+  LOOP
+    RAISE NOTICE '%', a;
+    a := COALESCE((a)."NU", (a)[2]);
+  END LOOP;
+END
+$$ LANGUAGE plpgsql;
+NOTICE:  {"": 6, "NU": [{"": [[3]]}, [6], [2], "bCi"], "aaf": [-6, -8]}
+NOTICE:  [{"": [[3]]}, [6], [2], "bCi"]
+NOTICE:  [2]
 
works fine.  I guess that is good enough.  Should we add these to the sql/jsonb.sql to document the expected behavior, both with the error when using plain "a" and with the correct output when using "(a)"?  The reason I mention this is that the plpgsql parser might get changed at some point, and without a test case, we might not notice if this breaks.


Yes, I think so.


cheers


andrew



--
Andrew Dunstan
EDB: https://www.enterprisedb.com
--------------mJjCjgQgAKQVSfqcp9bI35ec--