From: | Alexandra Wang <alexandra(dot)wang(dot)oss(at)gmail(dot)com> |
---|---|
To: | Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> |
Cc: | PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Nikita Glukhov <glukhov(dot)n(dot)a(at)gmail(dot)com>, jian he <jian(dot)universality(at)gmail(dot)com>, Nikita Malakhov <hukutoc(at)gmail(dot)com>, Vik Fearing <vik(at)postgresfriends(dot)org>, Mark Dilger <mark(dot)dilger(at)enterprisedb(dot)com>, Matheus Alcantara <matheusssilv97(at)gmail(dot)com>, Peter Eisentraut <peter(at)eisentraut(dot)org>, Andrew Dunstan <andrew(at)dunslane(dot)net>, "David E(dot) Wheeler" <david(at)justatheory(dot)com> |
Subject: | Re: SQL:2023 JSON simplified accessor support |
Date: | 2025-09-24 01:05:26 |
Message-ID: | CAK98qZ0R1ufQ-uQq8DxOPnmfacrzxBKy1phbUt8TA6+EDj9+PA@mail.gmail.com |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Hi Chao,
Thanks for reviewing. I'm glad you like the new approach of
introducing "transform_partial". I've attached v22, which addresses
some of your feedback, and I ran pgindent again.
See detailed replies below.
On Mon, Sep 22, 2025 at 10:48 PM Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> wrote:
> The new approach of introducing “transform_partial” looks like a better
> solution, which leads to less code change to hstore_subs and arraysubs.
> However, when I tested the v21, I encountered errors when combine composite
> type, array and jsonb together.
>
> Prepare test data:
> ```
> drop table if exists people;
> drop type if exists person;
> CREATE TYPE person AS (
> name text,
> size int[],
> meta jsonb[]
> );
>
> CREATE TABLE people (
> p person
> );
>
> INSERT INTO people VALUES (ROW('Alice', array[10, 20], array['{"a":
> 30}'::jsonb, '{"a": 40}'::jsonb]));
> ```
>
> Then run the test:
> ```
> # old jsonb accessor works to extract a jsonb field from an array item of
> a composite field
> evantest=# select (p).meta[1]->'a' from people;
> ?column?
> ----------
> 30
> (1 row)
>
> # dot notation also works
> evantest=# select (p).meta[1].a from people;
> a
> ----
> 30
> (1 row)
>
> # but index accessor doesn’t work
> evantest=# select (p).meta[1]['a'] from people;
> ERROR: invalid input syntax for type integer: "a"
> LINE 1: select (p).meta[1]['a'] from people;
> ^
>
This is the expected behavior for array subscripting, and my patch
doesn't change that. I don't think this is a problem. With or without
my patch, you can avoid the ERROR by adding parentheses:
test=# select ((p).meta[1])['a'] from people; meta ------ 30 (1 row)
On Mon, Sep 22, 2025 at 10:48 PM Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> wrote:
> 2 - 0002
> ```
> + /* Collect leading A_Indices subscripts */
> + foreach(lc, indirection)
> + {
> + Node *n = lfirst(lc);
> +
> + if (IsA(n, A_Indices))
> + {
> + A_Indices *ai = (A_Indices *) n;
> +
> + subscriptlist = lappend(subscriptlist, n);
> + if (ai->is_slice)
> + isSlice = true;
> + }
> + else
> + break;
> ```
>
> We can break after “isSlice=true”.
>
Why? We still want to get the whole prefix list of A_Indices.
On Mon, Sep 22, 2025 at 10:48 PM Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> wrote:
> 6 - 0002
> ```
> + /* This should not happen with well-behaved transform functions */
> + elog(ERROR, "subscripting transform function failed to consume any
> indirection elements”);
> ```
>
> I don’t see an existing error message uses “indirection” and “transform”.
> This error message looks more like a log message rather than a message to
> show to end users.
>
This is a defensive elog message that should not happen. So it is a
log message for developers. That said, I'm open to suggestions for
better wording.
The rest of your feedback I've made changes accordingly as you suggested.
Best,
Alex
Attachment | Content-Type | Size |
---|---|---|
v22-0005-Implement-read-only-dot-notation-for-jsonb.patch | application/octet-stream | 74.6 KB |
v22-0004-Extract-coerce_jsonpath_subscript.patch | application/octet-stream | 5.5 KB |
v22-0001-Add-test-coverage-for-indirection-transformation.patch | application/octet-stream | 6.9 KB |
v22-0002-Add-an-alternative-transform-function-in-Subscri.patch | application/octet-stream | 15.9 KB |
v22-0003-Export-jsonPathFromParseResult.patch | application/octet-stream | 2.8 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2025-09-24 01:23:08 | Re: Inconsistent Behavior of GROUP BY ROLLUP in v17 vs master |
Previous Message | John Naylor | 2025-09-24 01:04:59 | Re: a couple of small patches for simd.h |