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



Reply via email to