Re: SQL:2023 JSON simplified accessor support
Alexandra Wang <alexandra.wang.oss@gmail.com>
From: Alexandra Wang <alexandra.wang.oss@gmail.com>
To: jian he <jian.universality@gmail.com>,
Andrew Dunstan <andrew@dunslane.net>
Cc: Peter Eisentraut <peter@eisentraut.org>,
PostgreSQL Hackers <pgsql-hackers@postgresql.org>, david@justatheory.com
Date: 2024-11-07T21:57:58Z
Lists: pgsql-hackers
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Add test coverage for indirection transformation
- 64492917280a 19 (unreleased) landed
-
Fix typo in comment
- 81a61fde84ff 19 (unreleased) landed
-
Implementation of subscripting for jsonb
- 676887a3b0b8 14.0 cited
Attachments
- v5-0001-Add-JSON-JSONB-simplified-accessor.patch (application/x-patch) patch v5-0001
On Fri, Oct 4, 2024 at 7:33 AM jian he <jian.universality@gmail.com> wrote:
>
> On Thu, Sep 26, 2024 at 11:45 PM Alexandra Wang
> <alexandra.wang.oss@gmail.com> wrote:
> >
> > Hi,
> >
> > I didn’t run pgindent earlier, so here’s the updated version with the
> > correct indentation. Hope this helps!
> >
>
> the attached patch solves the domain type issue, Andrew mentioned in the thread.
>
> I also added a test case: composite over jsonb domain type,
>
>
> it still works. for example:
> create domain json_d as jsonb;
> create type test as (a int, b json_d);
> create table t1(a test);
> insert into t1 select $$(1,"{""a"": 3, ""key1"": {""c"": ""42""},
> ""key2"": [11, 12]}") $$;
> insert into t1 select $$ (1,"{""a"": 3, ""key1"": {""c"": ""42""},
> ""key2"": [11, 12, {""x"": [31, 42]}]}") $$;
>
> select (t1.a).b.key2[2].x[1] from t1;
> select (t1.a).b.key1.c from t1;
Thank you so much, Jian, for reviewing the patch and providing a fix!
I’ve integrated your fix into the attached v5 patch. Inspired by your
test case, I discovered another issue with domains over JSON:
top-level JSON array access to a domain over JSON when the domain is a
field of a composite type. Here’s an example:
create domain json_d as json;
create type test as (a int, b json_d);
create table t1(a test);
insert into t1 select $$ (1,"[{""a"": 3}, {""key1"": {""c"": ""42""}},
{""key2"": [11, 12]}]") $$;
select (t1.a).b[0] from t1;
The v5 patch includes the following updates:
- Fixed the aforementioned issue and added more tests covering composite
types with domains, nested domains, and arrays of domains over
JSON/JSONB.
- Refactored the logic for parsing JSON/JSONB object fields by moving it
from ParseFuncOrColumn() to transformIndirection() for improved
readability. The ParseFuncOrColumn() function is already handling both
single-argument function calls and composite types, and it has other
callers besides transformIndirection().
Best,
Alex