From: | Michael Paquier <michael(at)paquier(dot)xyz> |
---|---|
To: | Jan Przemysław Wójcik <jan(dot)przemyslaw(dot)wojcik(at)gmail(dot)com> |
Cc: | pgsql-bugs(at)lists(dot)postgresql(dot)org, Nikita Glukhov <n(dot)gluhov(at)postgrespro(dot)ru>, Alexander Korotkov <a(dot)korotkov(at)postgrespro(dot)ru> |
Subject: | Re: Unexpected extra row from jsonb_path_query() with a recursive path |
Date: | 2019-12-09 07:28:56 |
Message-ID: | 20191209072856.GA71819@paquier.xyz |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
(Adding Alexander and Nikita in CC.)
On Sun, Dec 08, 2019 at 12:43:18PM +0100, Jan Przemysław Wójcik wrote:
> select jsonb_path_query('{"data": [{"key": "value"}]}', '$.**.key')
>
> Actual output:
>
> jsonb_path_query
> ------------------
> "value"
> "value"
> (2 rows)
>
> Expected output:
>
> jsonb_path_query
> ------------------
> "value"
> (1 row)
So... .** means that it processes all the levels of the JSON
hierarchy and that it returns all the member values, including all the
members of an array as well as the array itself. Hence, based on your
previous example we have that:
=# select jsonb_path_query('{"data": [{"key": "value"}]}', '$.**');
jsonb_path_query
------------------------------
{"data": [{"key": "value"}]}
[{"key": "value"}]
{"key": "value"}
"value"
(4 rows)
that's what I would expect here with both the array and each one of
its elements to be selected.
Hence the question of Jan would be I guess the following: should the
value of first element of the array be selected or not in this case?
I am not completely sure if that's the wanted behavior or not, but I
would expect {"key": "value"} to be the only part selected, and only
one value to be returned, so this smells like a bug. Jan, is that
what you meant?
Alexander, Nikita, any opinions to offer?
--
Michael
From | Date | Subject | |
---|---|---|---|
Next Message | Michael Paquier | 2019-12-09 08:03:16 | Re: Warning in the RecordTransactionAbort routine during compilation with O3 flag |
Previous Message | Andrey Lepikhov | 2019-12-09 03:49:26 | Warning in the RecordTransactionAbort routine during compilation with O3 flag |