pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Thomas Kellerer <spam_eater@gmx.net>
To: pgsql-general@lists.postgresql.org
Subject: Re: A little confusion about JSON Path
Date: Fri, 18 Oct 2019 09:04:54 +0200
Message-ID: <ce47cf6f-6c1e-8172-88b5-31991fbf7dbc@gmx.net> (raw)
In-Reply-To: <1df6657c0e93e58791273e6389a2500b15efd0cd.camel@cybertec.at>
References: <8dcb9b9d-4863-b7e9-c3dc-e4ab2d01e918@gmx.net>
	<1df6657c0e93e58791273e6389a2500b15efd0cd.camel@cybertec.at>

Laurenz Albe schrieb am 17.10.2019 um 13:25:
>> I don't understand why the following two JSON Path expressions aren't doing the same thing in Postgres 12:
>>
>>  jsonb_path_exists(data, '$.k1.list.type() ? (@ == "array")'), -- returns true as expected
>>  jsonb_path_exists(data, '$.k1.list ? (@.type() == "array")') -- returns false - not expected
>>
>> Apparently "@.type()" returns something different then "$.k1.list.type()"
>>
> This seems to be a consequence of "lax" mode:
> 
>  "Besides, comparison operators automatically unwrap their operands in the lax mode,
>   so you can compare SQL/JSON arrays out-of-the-box. An array of size 1 is considered
>   equal to its sole element. Automatic unwrapping is not performed only when:
> 
>   - The path expression contains type() or size() methods that return the type and
>     the number of elements in the array, respectively.
> 
> (from https://www.postgresql.org/docs/12/functions-json.html)
> 
> with sample (data) as (
>   values
>     ('{"k1": {"list":[1,2,3]}}'::jsonb)
> )
> select data,
>        jsonb_path_exists(data, '$.k1.list ? (@.type() == "number")'),       -- lax mode unwraps the array
>        jsonb_path_exists(data, 'strict $.k1.list ? (@.type() == "array")')  -- strict mode doesn't
> from sample;


Ah, thanks. I did not see that part. 







view thread (3+ messages)

Message-ID: <ce47cf6f-6c1e-8172-88b5-31991fbf7dbc@gmx.net>
Permalink:  ../ce47cf6f-6c1e-8172-88b5-31991fbf7dbc@gmx.net/
Also on:    postgresql.org/message-id/ce47cf6f-6c1e-8172-88b5-31991fbf7dbc@gmx.net

 · 

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 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-general@postgresql.org
  Cc: spam_eater@gmx.net
  Subject: Re: A little confusion about JSON Path
  In-Reply-To: <ce47cf6f-6c1e-8172-88b5-31991fbf7dbc@gmx.net>
  References: <8dcb9b9d-4863-b7e9-c3dc-e4ab2d01e918@gmx.net> <1df6657c0e93e58791273e6389a2500b15efd0cd.camel@cybertec.at> <ce47cf6f-6c1e-8172-88b5-31991fbf7dbc@gmx.net>

* 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