jsonb array-style subscripting

From: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: jsonb array-style subscripting
Date: 2015-08-17 17:57:48
Message-ID: CA+q6zcV8qvGcDXurwwgUbwACV86Th7G80pnubg42e-p9gsSf=g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

Some time ago the array-style subscripting for the jsonb data type was
discussed in this mailing list. I think it will be quite convenient to have
a such nice syntax to update jsonb objects, so I'm trying to implement
this. I created a patch, that allows doing something like this:

=# create TEMP TABLE test_jsonb_subscript (
id int,
test_json jsonb
);

=# insert into test_jsonb_subscript values
(1, '{}'),
(2, '{}');

=# update test_jsonb_subscript set test_json['a']['a1']['a2'] = 42;
=# select * from test_jsonb_subscript;
id | test_json
----+--------------------------
1 | {"a": {"a1": {"a2": 42}}}
2 | {"a": {"a1": {"a2": 42}}}
(2 rows)

=# select test_json['a']['a1'] from test_jsonb_subscript;
test_json
------------
{"a2": 42}
{"a2": 42}
(2 rows)

This patch has a status "work in progress" of course. Generally speaking,
this implementation extends the `ArrayRef` usage for the jsonb.
And I need some sort of advice about several questions:

* is it interesting for the community?
* is that a good idea to extend the `ArrayRef` for jsonb? If it's
appropriate, probably we can rename it to `ArrayJsonbRef` of something.
* what can be improved in the code at the top level (function placement,
probably, functionality duplication, etc.)?
* are there any special cases, that I should take care of in this
implementation?

Attachment Content-Type Size
jsonb_subscript2.patch application/octet-stream 25.4 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2015-08-17 18:50:45 missing documentation for partial WAL files
Previous Message Andrew Dunstan 2015-08-17 17:44:14 Re: More WITH