Re: Unexpected extra row from jsonb_path_query() with a recursive path
Michael Paquier <[email protected]>
| Newsgroups | gmane.comp.db.postgresql.bugs |
|---|---|
| Message-ID | <[email protected]> |
(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
signature.asc
(application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAl3t97gACgkQnvQgOdby QH1gjQ//TrygZBXmrtb2nv40wgyuQW47HZZNQOy5wZWY+/dU1oqrRaeiUMeOejM+ 4EJ4UGlcmK9Yrqbg03vEl9BeMR0rdCkm2g/IouHpaItVK6h1iKEHX9I3fJ+sXqO7 n5/IGl0CH9d7OiAgNwVmXM08qHGzrZYSDRJVciSmc1QEy7FEHuLxPrEbKhohJrdT UYC141JjWpM8rbiKpN3yTbkKK6nVKTfa5C76Vbypm8G5QqUQEHVXm0eOtaAdiH1p SYJA+R47t7uNFjO7165wIAhR7S+6zaTgtz/7znu77wICTHJuQD9+fUHoBxWZjO+h qrzi/mejfJEXivF4B2WJTTaH38CGNOxTyZUt2W9yUaFnxfyugyHiBbC4qJb2AT2R LyxbXBN5WM+6DgRJgFR5/BaMDCveB2uQ7Oh3KGzyKeKHfPBwPZhhhGnBrBz162wc w0vJV7I8QJ1Ay94Duwsw27OhhCn7MBjGOq6JBXSXFUTHFVknDtPpz2YFkLWAFxHW gQs1d6iBv271zBVGiPeZR/6w/d9b/NPyC3qw9BruPITUDxHxVEtekfF9mDpg+p76 bupfUUZ/kF2ACrtwQX5qJk4uH67zg3lZ4AE+SqjHUqiWVnE0DVVVpsgqKJQVsNoc 89LeW6Hnd5eb7bmty2QaqThAbFZrWX8JdOWT0Jt1tj6ZtS8totg= =/+4K -----END PGP SIGNATURE-----