Re: SQL:2023 JSON simplified accessor support

From: Alexandra Wang <alexandra(dot)wang(dot)oss(at)gmail(dot)com>
To: jian he <jian(dot)universality(at)gmail(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: Peter Eisentraut <peter(at)eisentraut(dot)org>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, david(at)justatheory(dot)com
Subject: Re: SQL:2023 JSON simplified accessor support
Date: 2024-11-07 21:57:58
Message-ID: CAK98qZ3Hv6ndh2vaCyGUSdyE7AXTvCLUSYKTdHp2kaPDnp6S4w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Oct 4, 2024 at 7:33 AM jian he <jian(dot)universality(at)gmail(dot)com> wrote:
>
> On Thu, Sep 26, 2024 at 11:45 PM Alexandra Wang
> <alexandra(dot)wang(dot)oss(at)gmail(dot)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

Attachment Content-Type Size
v5-0001-Add-JSON-JSONB-simplified-accessor.patch application/x-patch 37.8 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2024-11-07 22:27:30 Re: Alias of VALUES RTE in explain plan
Previous Message Devulapalli, Raghuveer 2024-11-07 21:42:58 RE: Use __attribute__((target(sse4.2))) for SSE42 CRC32C