jsonpath: Missing regex_like && starts with Errors?

From: "David E(dot) Wheeler" <david(at)justatheory(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: jsonpath: Missing regex_like && starts with Errors?
Date: 2024-06-14 16:21:23
Message-ID: 9272D3A9-8805-4DE1-A95F-84EB210EC121@justatheory.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hackers,

I noticed that neither `regex_like` nor `starts with`, the jsonpath operators, raise an error when the operand is not a string (or array of strings):

david=# select jsonb_path_query('true', '$ like_regex "^hi"');
jsonb_path_query
------------------
null
(1 row)

david=# select jsonb_path_query('{"x": "hi"}', '$ starts with "^hi"');
jsonb_path_query
------------------
null
(1 row)

This is true in strict and lax mode, and with verbosity enabled (as in these examples). Most other operators raise an error when they can’t operate on the operand:

david=# select jsonb_path_query('{"x": "hi"}', '$.integer()');
ERROR: jsonpath item method .integer() can only be applied to a string or numeric value

david=# select jsonb_path_query('{"x": "hi"}', '$+$');
ERROR: left operand of jsonpath operator + is not a single numeric value

Should `like_regex` and `starts with` adopt this behavior, too?

I note that filter expressions seem to suppress these sorts of errors, but I assume that’s by design:

david=# select jsonb_path_query('{"x": "hi"}', 'strict $ ?(@ starts with "^hi")');
jsonb_path_query
------------------
(0 rows)

david=# select jsonb_path_query('{"x": "hi"}', 'strict $ ?(@ like_regex "^hi")');
jsonb_path_query
------------------
(0 rows)

david=# select jsonb_path_query('{"x": "hi"}', 'strict $ ?(@.integer() == 1)');
jsonb_path_query
------------------
(0 rows)

D

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2024-06-14 16:25:30 Re: Using LibPq in TAP tests via FFI
Previous Message Andres Freund 2024-06-14 16:17:25 Re: RFC: adding pytest as a supported test framework