jsonpath: Missing regex_like && starts with Errors? - Mailing list pgsql-hackers

From David E. Wheeler
Subject jsonpath: Missing regex_like && starts with Errors?
Date
Msg-id 9272D3A9-8805-4DE1-A95F-84EB210EC121@justatheory.com
Whole thread Raw
Responses Re: jsonpath: Missing regex_like && starts with Errors?
List 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
errorwhen 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




pgsql-hackers by date:

Previous
From: Andres Freund
Date:
Subject: Re: RFC: adding pytest as a supported test framework
Next
From: Andres Freund
Date:
Subject: Re: Using LibPq in TAP tests via FFI