Hi,

While testing the new json_path method split_part(), I noticed that it doesn’t 
honor silent mode. I think this is a v19-new bug.

This is a simple repro:
```
evantest=# select jsonb_path_query('"a,b"', '$.split_part(",", 0)');
ERROR:  field position must not be zero
evantest=# select jsonb_path_query('"a,b"', '$.split_part(",", 0)', silent => 
true);
ERROR:  field position must not be zero
evantest=# select jsonb_path_query('"a,b"', '$.split_part(",", 2147483648)');
ERROR:  integer out of range
evantest=# select jsonb_path_query('"a,b"', '$.split_part(",", 2147483648)', 
silent => true);
ERROR:  integer out of range
```

As a comparison, an existing method such as .decimal() suppresses similar 
argument errors in silent mode:
```
evantest=# select jsonb_path_query('12.3', '$.decimal(12345678901,1)');
ERROR:  precision of jsonpath item method .decimal() is out of range for type 
integer
evantest=# select jsonb_path_query('12.3', '$.decimal(12345678901,1)', silent 
=> true);
 jsonb_path_query
------------------
(0 rows)
```

After looking into the code, I think the root cause is that .decimal() uses 
numeric_int4_safe() to parse integer arguments, while the .split_part() path in 
executeStringInternalMethod() uses numeric_int4() directly, which raises an 
error immediately for invalid values.

The attached patch fixes this by switching the .split_part() path to use 
numeric_int4_safe() and report the argument errors through the jsonpath error 
handling mechanism.

Please see the attached patch for details.

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/




Attachment: v1-0001-Fix-jsonpath-.split_part-to-honor-silent-mode.patch
Description: Binary data

Reply via email to