public inbox for [email protected]
help / color / mirror / Atom feedFrom: Peter Eisentraut <[email protected]>
To: Amit Langote <[email protected]>
Cc: pgsql-hackers <[email protected]>
Subject: Re: json_query conditional wrapper bug
Date: Tue, 10 Sep 2024 22:15:55 +0200
Message-ID: <[email protected]> (raw)
In-Reply-To: <CA+HiwqFARj1L-HPa+ESbK3ZvUTYt0MpFdrE2vjVjhF2oxXSK-g@mail.gmail.com>
References: <[email protected]>
<[email protected]>
<CA+HiwqFARj1L-HPa+ESbK3ZvUTYt0MpFdrE2vjVjhF2oxXSK-g@mail.gmail.com>
On 10.09.24 10:00, Amit Langote wrote:
> Sorry for missing this report and thanks Andrew for the offlist heads up.
>
> On Wed, Sep 4, 2024 at 7:16 PM Peter Eisentraut <[email protected]> wrote:
>> On 28.08.24 11:21, Peter Eisentraut wrote:
>>> These are ok:
>>>
>>> select json_query('{"a": 1, "b": 42}'::jsonb, 'lax $.b' without wrapper);
>>> json_query
>>> ------------
>>> 42
>>>
>>> select json_query('{"a": 1, "b": 42}'::jsonb, 'lax $.b' with
>>> unconditional wrapper);
>>> json_query
>>> ------------
>>> [42]
>>>
>>> But this appears to be wrong:
>>>
>>> select json_query('{"a": 1, "b": 42}'::jsonb, 'lax $.b' with conditional
>>> wrapper);
>>> json_query
>>> ------------
>>> [42]
>>>
>>> This should return an unwrapped 42.
>>
>> If I make the code change illustrated in the attached patch, then I get
>> the correct result here. And various regression test results change,
>> which, to me, all look more correct after this patch. I don't know what
>> the code I removed was supposed to accomplish, but it seems to be wrong
>> somehow. In the current implementation, the WITH CONDITIONAL WRAPPER
>> clause doesn't appear to work correctly in any case I could identify.
>
> Agreed that this looks wrong.
>
> I've wondered why the condition was like that but left it as-is,
> because I thought at one point that that's needed to ensure that the
> returned single scalar SQL/JSON item is valid jsonb.
>
> I've updated your patch to include updated test outputs and a nearby
> code comment expanded. Do you intend to commit it or do you prefer
> that I do?
This change looks unrelated:
-ERROR: new row for relation "test_jsonb_constraints" violates check
constraint "test_jsonb_constraint4"
+ERROR: new row for relation "test_jsonb_constraints" violates check
constraint "test_jsonb_constraint5"
Is this some randomness in the way these constraints are evaluated?
view thread (5+ messages)
reply
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 using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected]
Subject: Re: json_query conditional wrapper bug
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox