Shouldn't jsonpath .string() Unwrap?

From: "David E(dot) Wheeler" <david(at)justatheory(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Shouldn't jsonpath .string() Unwrap?
Date: 2024-06-08 22:49:38
Message-ID: A64AE04F-4410-42B7-A141-7A7349260F4D@justatheory.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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?

Best,

David

[1]: https://github.com/postgres/postgres/blob/REL_17_BETA1/src/test/regress/expected/jsonb_jsonpath.out#L2527-L2530

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Joseph Koshakow 2024-06-09 01:13:07 Re: Wrong security context for deferred triggers?
Previous Message Tom Lane 2024-06-08 22:21:24 Re: Windows: openssl & gssapi dislike each other