Re: Shouldn't jsonpath .string() Unwrap? - Mailing list pgsql-hackers

From David G. Johnston
Subject Re: Shouldn't jsonpath .string() Unwrap?
Date
Msg-id CAKFQuwacXyOuRCkQZaJmzXu2jkPz629GFZS2AdjZa8T32FKDow@mail.gmail.com
Whole thread Raw
In response to Shouldn't jsonpath .string() Unwrap?  ("David E. Wheeler" <david@justatheory.com>)
Responses Re: Shouldn't jsonpath .string() Unwrap?
Re: Shouldn't jsonpath .string() Unwrap?
List pgsql-hackers
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.

David J.

pgsql-hackers by date:

Previous
From: Michail Nikolaev
Date:
Subject: Re: race condition in pg_class
Next
From: "David E. Wheeler"
Date:
Subject: Re: Shouldn't jsonpath .string() Unwrap?