Re: [HACKERS] [PATCH] Generic type subscripting - Mailing list pgsql-hackers

From Oleksandr Shulgin
Subject Re: [HACKERS] [PATCH] Generic type subscripting
Date
Msg-id CACACo5Sioo62z8RdXHvRqJtFZf8=D+EzwEXDueXnOpgnNbU3uw@mail.gmail.com
Whole thread Raw
In response to Re: [HACKERS] [PATCH] Generic type subscripting  (Dmitry Dolgov <9erthalion6@gmail.com>)
Responses Re: [HACKERS] [PATCH] Generic type subscripting  (Dmitry Dolgov <9erthalion6@gmail.com>)
List pgsql-hackers
On Tue, Mar 6, 2018 at 6:21 PM, Dmitry Dolgov <9erthalion6@gmail.com> wrote:

One more small update after fd1a421fe6 in attachments.

Before looking at the code I have a few comments about documentation:

in json.sgml:

+-- Extract value by key
+SELECT ('{"a": 1}'::jsonb)['a'];

What is the result of running this query?  What is the resulting data type?

+-- Extract nested value by key path
+SELECT ('{"a": {"b": {"c": 1}}}'::jsonb)['a']['b']['c'];
+
+-- Extract element by index
+SELECT ('[1, "2", null]'::jsonb)['1'];

What is the result here?  Why subscript is a string and not a number?  Are subscription indexes 0- or 1-based?

+-- Update value by key
+UPDATE table_name set jsonb_field['key'] = 1;
+
+-- Select records using where clause with subscripting
+SELECT * from table_name where jsonb_field['key'] = '"value"';

Please capitalize: SET, FROM, WHERE.

Use of double quotes around "value" requires some explanation, I think.
Should the user expect that a suitable index is used by the query planner for this query?

In other words, I would like to see this part of documentation to be extended beyond just showcasing the syntax.

Regards,
--
Oleksandr "Alex" Shulgin | Database Engineer | Zalando SE | Tel: +49 176 127-59-707

pgsql-hackers by date:

Previous
From: Andrew Gierth
Date:
Subject: Re: PostgreSQL 10: Segmentation fault when using GROUPING SETS with all unsortable columns
Next
From: Andres Freund
Date:
Subject: Re: JIT compiling with LLVM v12.2