From: Michael Paquier <michael@paquier.xyz>
To: Jan Przemysław Wójcik <jan.przemyslaw.wojcik@gmail.com>
Cc: pgsql-bugs@lists.postgresql.org, Nikita Glukhov <n.gluhov@postgrespro.ru>
Cc: Alexander Korotkov <a.korotkov@postgrespro.ru>
Subject: Re: Unexpected extra row from jsonb_path_query() with a recursive path
Date: Mon, 9 Dec 2019 16:28:56 +0900
Message-ID: <20191209072856.GA71819@paquier.xyz> (raw)
In-Reply-To: <CA+YsLFo6=voUdskxNcnJdqN4Z+Kck-5t0MxcJNtecNZ5Sws9YA@mail.gmail.com>
References: <CA+YsLFo6=voUdskxNcnJdqN4Z+Kck-5t0MxcJNtecNZ5Sws9YA@mail.gmail.com>
(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
Attachments:
signature.asc (application/pgp-signature, 832B) download
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: michael@paquier.xyz, jan.przemyslaw.wojcik@gmail.com, n.gluhov@postgrespro.ru, a.korotkov@postgrespro.ru
Subject: Re: Unexpected extra row from jsonb_path_query() with a recursive path
In-Reply-To: <20191209072856.GA71819@paquier.xyz>
References: <CA+YsLFo6=voUdskxNcnJdqN4Z+Kck-5t0MxcJNtecNZ5Sws9YA@mail.gmail.com> <20191209072856.GA71819@paquier.xyz>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox