Re: SQL:2023 JSON simplified accessor support - Mailing list pgsql-hackers

From Alexandra Wang
Subject Re: SQL:2023 JSON simplified accessor support
Date
Msg-id CAK98qZ2EhKC=Z23jNbMX=aGPGi9+n42a8Eiz1rKYmF388UCHUQ@mail.gmail.com
Whole thread Raw
In response to Re: SQL:2023 JSON simplified accessor support  (Alexandra Wang <alexandra.wang.oss@gmail.com>)
List pgsql-hackers
Hi there,

I've attached v20. It has the following changes:

1. New 0001: It adds test coverage for single-argument functions and
casting for jsonb expressions. This ensures that the relevant behavior
changes become visible in 0005 when field access via dot-notation is
introduced.

Specifically, once member access through dot-notation is enabled for
jsonb, we can no longer write single-argument functions (including
casts) in dot form for jsonb. For example:

Before 0005: 

select ('{"a":1}'::jsonb).jsonb_typeof;
  jsonb_typeof
 --------------
 object
(1 row)

select ('[{"name": "alice"}, {"name": "bob"}]'::jsonb).name;
                 name
--------------------------------------
[{"name": "alice"}, {"name": "bob"}]
(1 row)

After 0005:

select ('{"a":1}'::jsonb).jsonb_typeof;
  jsonb_typeof
 --------------

(1 row)

select ('[{"name": "alice"}, {"name": "bob"}]'::jsonb).name;
       name
------------------
 ["alice", "bob"]
 (1 row)

In the meanwhile, these functions still return correct results through
standard syntax:

test=#  select jsonb_typeof(('{"a":1}'::jsonb));
 jsonb_typeof
--------------
 object
(1 row)
test=#  select ('[{"name": "alice"}, {"name": "bob"}]'::jsonb)::name;
                 name
--------------------------------------
 [{"name": "alice"}, {"name": "bob"}]
(1 row)

I don't consider this behavior change a major issue, because the
dot-form for single-argument functions is not standard SQL and seems
to be PostgreSQL-specific. Still, it's worth highlighting here so
users aren't surprised.

2. Refactored 0002: It combines and refactors v19-0001 and v19-0002.
Instead of changing the existing transform() callback in
SubscriptRoutines, it now introduces an additional callback,
transform_partial(). This alternative transform method, used by jsonb,
is more flexible: it accepts a wider range of indirection node types
and can transform only a prefix of the indirection list. This avoids
breaking compatibility for arrays, hstore, and external data types
that supports subscripting.

3. 0003 and 0004 stay unchanged. They are both small and can be squashed
into 0005. I leave them as-is for now for easier review.

4. Added two additional tests in 0005 for assignments using jsonb
dot-notation, showing explicitly that assignment is not yet supported.

5. Removed 0006 (array slicing) and 0007 (wildcard) from the previous
versions, as they need additional work. My immediate goal is to first
reach consensus on the dot-notation implementation.

Best,
Alex

Attachment

pgsql-hackers by date:

Previous
From: Sami Imseih
Date:
Subject: Re: [BUG] temporary file usage report with extended protocol and unnamed portals
Next
From: "Jonathan S. Katz"
Date:
Subject: Re: PG 18 relnotes and RC1