8.14.5 jsonb subscripting

Started by PG Bug reporting formabout 2 years ago15 messagesdocs
Jump to latest
#1PG Bug reporting form
noreply@postgresql.org

The following documentation comment has been logged on the website:

Page: https://www.postgresql.org/docs/16/datatype-json.html
Description:

Using subscripts with square brackets is not supported, one must use -> or
#> operators
The given examples result in error:

SELECT ('{"a": 1}'::jsonb)['a'];

-- Extract nested object value by key path
SELECT ('{"a": {"b": {"c": 1}}}'::jsonb)['a']['b']['c'];

-- Extract array element by index
SELECT ('[1, "2", null]'::jsonb)[1];

#2Laurenz Albe
laurenz.albe@cybertec.at
In reply to: PG Bug reporting form (#1)
Re: 8.14.5 jsonb subscripting

On Tue, 2024-04-09 at 09:31 +0000, PG Doc comments form wrote:

Page: https://www.postgresql.org/docs/16/datatype-json.html

Using subscripts with square brackets is not supported, one must use -> or
#> operators
The given examples result in error:

SELECT ('{"a": 1}'::jsonb)['a'];

-- Extract nested object value by key path
SELECT ('{"a": {"b": {"c": 1}}}'::jsonb)['a']['b']['c'];

-- Extract array element by index
SELECT ('[1, "2", null]'::jsonb)[1];

You must be using an old PostgreSQL version where that is not yet supported.

Yours,
Laurenz Albe

#3Arne Sommerfelt
arne.sommerfelt@gmail.com
In reply to: Laurenz Albe (#2)
Re: 8.14.5 jsonb subscripting

I am running on AWS RDS - it says engine version 12.17 i thought that was
the postgres version. If so, the [] subscripting should be supported
according to docs.

Arne

tir. 9. apr. 2024 kl. 13:16 skrev Laurenz Albe <laurenz.albe@cybertec.at>:

Show quoted text

On Tue, 2024-04-09 at 09:31 +0000, PG Doc comments form wrote:

Page: https://www.postgresql.org/docs/16/datatype-json.html

Using subscripts with square brackets is not supported, one must use ->

or

#> operators
The given examples result in error:

SELECT ('{"a": 1}'::jsonb)['a'];

-- Extract nested object value by key path
SELECT ('{"a": {"b": {"c": 1}}}'::jsonb)['a']['b']['c'];

-- Extract array element by index
SELECT ('[1, "2", null]'::jsonb)[1];

You must be using an old PostgreSQL version where that is not yet
supported.

Yours,
Laurenz Albe

#4Arne Sommerfelt
arne.sommerfelt@gmail.com
In reply to: Arne Sommerfelt (#3)
Re: 8.14.5 jsonb subscripting

I checked with SELECT VERSION(); and got:
PostgreSQL 12.17 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 7.3.1
20180712 (Red Hat 7.3.1-12), 64-bit

tir. 9. apr. 2024 kl. 15:05 skrev Arne Sommerfelt <arne.sommerfelt@gmail.com

Show quoted text

:

I am running on AWS RDS - it says engine version 12.17 i thought that was
the postgres version. If so, the [] subscripting should be supported
according to docs.

Arne

tir. 9. apr. 2024 kl. 13:16 skrev Laurenz Albe <laurenz.albe@cybertec.at>:

On Tue, 2024-04-09 at 09:31 +0000, PG Doc comments form wrote:

Page: https://www.postgresql.org/docs/16/datatype-json.html

Using subscripts with square brackets is not supported, one must use ->

or

#> operators
The given examples result in error:

SELECT ('{"a": 1}'::jsonb)['a'];

-- Extract nested object value by key path
SELECT ('{"a": {"b": {"c": 1}}}'::jsonb)['a']['b']['c'];

-- Extract array element by index
SELECT ('[1, "2", null]'::jsonb)[1];

You must be using an old PostgreSQL version where that is not yet
supported.

Yours,
Laurenz Albe

#5Tom Lane
tgl@sss.pgh.pa.us
In reply to: Arne Sommerfelt (#3)
Re: 8.14.5 jsonb subscripting

Arne Sommerfelt <arne.sommerfelt@gmail.com> writes:

I am running on AWS RDS - it says engine version 12.17 i thought that was
the postgres version. If so, the [] subscripting should be supported
according to docs.

According to what docs? Generic subscripting was added in v14.

regards, tom lane

#6Arne Sommerfelt
arne.sommerfelt@gmail.com
In reply to: Tom Lane (#5)
Re: 8.14.5 jsonb subscripting

[image: image.png]

tir. 9. apr. 2024 kl. 16:00 skrev Tom Lane <tgl@sss.pgh.pa.us>:

Show quoted text

Arne Sommerfelt <arne.sommerfelt@gmail.com> writes:

I am running on AWS RDS - it says engine version 12.17 i thought that was
the postgres version. If so, the [] subscripting should be supported
according to docs.

According to what docs? Generic subscripting was added in v14.

regards, tom lane

Attachments:

image.pngimage/png; name=image.pngDownload
#7Daniel Gustafsson
daniel@yesql.se
In reply to: Arne Sommerfelt (#6)
Re: 8.14.5 jsonb subscripting

On 9 Apr 2024, at 16:02, Arne Sommerfelt <arne.sommerfelt@gmail.com> wrote:

<image.png>

Thats the documentation for v16, not the version you are running.

--
Daniel Gustafsson

#8Arne Sommerfelt
arne.sommerfelt@gmail.com
In reply to: Arne Sommerfelt (#6)
Re: 8.14.5 jsonb subscripting

12 is in the list of supported versions at the top of chapter 8.14. And the
non-working examples is in subsection 8.14.5

tir. 9. apr. 2024 kl. 16:02 skrev Arne Sommerfelt <arne.sommerfelt@gmail.com

Show quoted text

:

[image: image.png]

tir. 9. apr. 2024 kl. 16:00 skrev Tom Lane <tgl@sss.pgh.pa.us>:

Arne Sommerfelt <arne.sommerfelt@gmail.com> writes:

I am running on AWS RDS - it says engine version 12.17 i thought that

was

the postgres version. If so, the [] subscripting should be supported
according to docs.

According to what docs? Generic subscripting was added in v14.

regards, tom lane

Attachments:

image.pngimage/png; name=image.pngDownload
#9Daniel Gustafsson
daniel@yesql.se
In reply to: Arne Sommerfelt (#8)
Re: 8.14.5 jsonb subscripting

On 9 Apr 2024, at 16:04, Arne Sommerfelt <arne.sommerfelt@gmail.com> wrote:

12 is in the list of supported versions at the top of chapter 8.14. And the non-working examples is in subsection 8.14.5

I think you've misunderstood the header of the page. This is the documentation
you should be reading for your version if Postgres:

https://www.postgresql.org/docs/12/index.html

--
Daniel Gustafsson

#10Arne Sommerfelt
arne.sommerfelt@gmail.com
In reply to: Daniel Gustafsson (#7)
Re: 8.14.5 jsonb subscripting

OK, sorry if am making unnecessary noise. Since my version was listed as
supported I assumed the docs was valid for me.

Thanks for your help
cheers
Arne

tir. 9. apr. 2024 kl. 16:04 skrev Daniel Gustafsson <daniel@yesql.se>:

Show quoted text

On 9 Apr 2024, at 16:02, Arne Sommerfelt <arne.sommerfelt@gmail.com>

wrote:

<image.png>

Thats the documentation for v16, not the version you are running.

--
Daniel Gustafsson

#11Arne Sommerfelt
arne.sommerfelt@gmail.com
In reply to: Daniel Gustafsson (#9)
Re: 8.14.5 jsonb subscripting

Thank you! When googling it is easy to end up with latest docs,
unfortunately

Arne

tir. 9. apr. 2024 kl. 16:06 skrev Daniel Gustafsson <daniel@yesql.se>:

Show quoted text

On 9 Apr 2024, at 16:04, Arne Sommerfelt <arne.sommerfelt@gmail.com>

wrote:

12 is in the list of supported versions at the top of chapter 8.14. And

the non-working examples is in subsection 8.14.5

I think you've misunderstood the header of the page. This is the
documentation
you should be reading for your version if Postgres:

https://www.postgresql.org/docs/12/index.html

--
Daniel Gustafsson

#12Daniel Gustafsson
daniel@yesql.se
In reply to: Arne Sommerfelt (#10)
Re: 8.14.5 jsonb subscripting

On 9 Apr 2024, at 16:07, Arne Sommerfelt <arne.sommerfelt@gmail.com> wrote:

OK, sorry if am making unnecessary noise. Since my version was listed as supported I assumed the docs was valid for me.

No worries, we're all here to learn. The "supported version" means that 12 is
a version which the project still supports with bugfixes.

--
Daniel Gustafsson

#13David G. Johnston
david.g.johnston@gmail.com
In reply to: Arne Sommerfelt (#11)
Re: 8.14.5 jsonb subscripting

On Tuesday, April 9, 2024, Arne Sommerfelt <arne.sommerfelt@gmail.com>
wrote:

Thank you! When googling it is easy to end up with latest docs,
unfortunately

The 12 is a hyperlink so it is almost just as easy to view the current page
in the prior version.

David J.

#14Tom Lane
tgl@sss.pgh.pa.us
In reply to: Arne Sommerfelt (#11)
Re: 8.14.5 jsonb subscripting

Arne Sommerfelt <arne.sommerfelt@gmail.com> writes:

Thank you! When googling it is easy to end up with latest docs,
unfortunately

That's actually good news --- it used to be that Google would
tend to steer people to very ancient versions of our docs.
Sounds like the SEO work that we've done is paying off.

However, if you're running a moderately old PG version, you need
to make use of the links at the top of the page to go to the
equivalent page in the older version's docs.

regards, tom lane

#15Arne Sommerfelt
arne.sommerfelt@gmail.com
In reply to: Tom Lane (#14)
Re: 8.14.5 jsonb subscripting

Thank you all for super prompt and friendly support.

Best regards
Arne

tir. 9. apr. 2024 kl. 16:26 skrev Tom Lane <tgl@sss.pgh.pa.us>:

Show quoted text

Arne Sommerfelt <arne.sommerfelt@gmail.com> writes:

Thank you! When googling it is easy to end up with latest docs,
unfortunately

That's actually good news --- it used to be that Google would
tend to steer people to very ancient versions of our docs.
Sounds like the SEO work that we've done is paying off.

However, if you're running a moderately old PG version, you need
to make use of the links at the top of the page to go to the
equivalent page in the older version's docs.

regards, tom lane