Example of json_array_elements

Started by PG Bug reporting formover 4 years ago2 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/12/functions-json.html
Description:

Maybe this example for json_array_elements is wrong?

select * from json_array_elements('[1,true, [2,false]]')

It seems to me that it should be

select * from json_array_elements('[[1,true], [2,false]]')

Thank you for this extraordinary documentation!

#2Daniel Gustafsson
daniel@yesql.se
In reply to: PG Bug reporting form (#1)
Re: Example of json_array_elements

On 12 Nov 2021, at 13:18, PG Doc comments form <noreply@postgresql.org> wrote:

Maybe this example for json_array_elements is wrong?

No, the example works as intended and yields the output in the documentation:

postgres=# select * from json_array_elements('[1,true, [2,false]]');
value
-----------
1
true
[2,false]
(3 rows)

Your proposal is also syntactically correct, but it's not what the author
intended when writing the example:

postgres=# select * from json_array_elements('[[1,true], [2,false]]');
value
-----------
[1,true]
[2,false]
(2 rows)

--
Daniel Gustafsson https://vmware.com/