Re: Shouldn't jsonpath .string() Unwrap?
Andrew Dunstan <andrew@dunslane.net>
From: Andrew Dunstan <andrew@dunslane.net>
To: "David G. Johnston" <david.g.johnston@gmail.com>,
"David E. Wheeler" <david@justatheory.com>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>,
Jeevan Chalke <jeevan.chalke@enterprisedb.com>
Date: 2024-06-13T19:53:17Z
Lists: pgsql-hackers
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Teach jsonpath string() to unwrap in lax mode
- 653d3969bb01 17.0 landed
On 2024-06-12 We 16:02, David G. Johnston wrote:
> On Sat, Jun 8, 2024 at 3:50 PM David E. Wheeler
> <david@justatheory.com> wrote:
>
> Hackers,
>
> Most of the jsonpath methods auto-unwrap in lax mode:
>
> david=# select jsonb_path_query('[-2,5]', '$.abs()');
> jsonb_path_query
> ------------------
> 2
> 5
> (2 rows)
>
> The obvious exceptions are size() and type(), which apply directly
> to arrays, so no need to unwrap:
>
> david=# select jsonb_path_query('[-2,5]', '$.size()');
> jsonb_path_query
> ------------------
> 2
> (1 row)
>
> david=# select jsonb_path_query('[-2,5]', '$.type()');
> jsonb_path_query
> ------------------
> "array"
>
> But what about string()? Is there some reason it doesn’t unwrap?
>
> david=# select jsonb_path_query('[-2,5]', '$.string()');
> ERROR: jsonpath item method .string() can only be applied to a
> bool, string, numeric, or datetime value
>
> What I expect:
>
> david=# select jsonb_path_query('[-2,5]', '$.string()');
> jsonb_path_query
> —————————
> "2"
> "5"
> (2 rows)
>
> However, I do see a test[1] for this behavior, so maybe there’s a
> reason for it?
>
>
> Adding Andrew.
>
> I'm willing to call this an open item against this feature as I don't
> see any documentation explaining that string() behaves differently
> than the others.
>
>
Hmm. You might be right. Many of these items have this code, but the
string() branch does not:
if (unwrap && JsonbType(jb) == jbvArray)
return executeItemUnwrapTargetArray(cxt, jsp, jb, found,
false);
cheers
andrew
--
Andrew Dunstan
EDB:https://www.enterprisedb.com