Re: json_query - redundant result

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Oleg Bartunov <obartunov(at)gmail(dot)com>
Subject: Re: json_query - redundant result
Date: 2022-04-28 14:00:53
Message-ID: 575731.1651154453@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Andrew Dunstan <andrew(at)dunslane(dot)net> writes:
> On 2022-04-28 Th 04:16, Pavel Stehule wrote:
>> Is this result correct? I am expecting just [10, 30]

> It's just a wrapper around jsonb_path_query, which hasn't changed.

> # SELECT jsonb_path_query(jsonb '[{"a":10, "b": 20}, {"a": 30,
> "b":100}]', '$.**.a');
>  jsonb_path_query
> ------------------
>  10
>  30
>  10
>  30
> (4 rows)

> If that's a bug it's not a new one - release 14 gives the same result.

I'm pretty clueless in this area, but I think this might have to do with
the "lax mode" described in 9.16.2.1:

https://www.postgresql.org/docs/devel/functions-json.html#FUNCTIONS-SQLJSON-PATH

regression=# SELECT jsonb_path_query(jsonb '[{"a":10, "b": 20}, {"a": 30,
regression'# "b":100}]', '$.**.a');
jsonb_path_query
------------------
10
30
10
30
(4 rows)

regression=# SELECT jsonb_path_query(jsonb '[{"a":10, "b": 20}, {"a": 30,
"b":100}]', 'strict $.**.a');
jsonb_path_query
------------------
10
30
(2 rows)

Maybe these SQL-standard syntaxes ought to default to strict mode?

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Pavel Stehule 2022-04-28 14:06:28 Re: json_query - redundant result
Previous Message Tom Lane 2022-04-28 13:55:08 Re: src / test / regress / sql / triggers.sql first 10 lines.