Fix jsonpath .split_part() to honor silent mode

Started by Chao Li13 days ago5 messageshackers
Jump to latest
#1Chao Li
li.evan.chao@gmail.com

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/

Attachments:

v1-0001-Fix-jsonpath-.split_part-to-honor-silent-mode.patchapplication/octet-stream; name=v1-0001-Fix-jsonpath-.split_part-to-honor-silent-mode.patch; x-unix-mode=0644Download+34-4
#2Nazir Bilal Yavuz
byavuz81@gmail.com
In reply to: Chao Li (#1)
Re: Fix jsonpath .split_part() to honor silent mode

Hi,

Thank you for working on this!

On Tue, 12 May 2026 at 05:11, Chao Li <li.evan.chao@gmail.com> wrote:

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.

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.

I think you are right and I confirm that your patch fixes the problem.

--
Regards,
Nazir Bilal Yavuz
Microsoft

#3Michael Paquier
michael@paquier.xyz
In reply to: Nazir Bilal Yavuz (#2)
Re: Fix jsonpath .split_part() to honor silent mode

On Wed, May 13, 2026 at 12:57:50PM +0300, Nazir Bilal Yavuz wrote:

I think you are right and I confirm that your patch fixes the problem.

Indeed, good catch! I'll go double-check the area before doing
something. Thanks for the report!
--
Michael

#4Andrew Dunstan
andrew@dunslane.net
In reply to: Michael Paquier (#3)
Re: Fix jsonpath .split_part() to honor silent mode

On 2026-05-14 Th 2:02 AM, Michael Paquier wrote:

On Wed, May 13, 2026 at 12:57:50PM +0300, Nazir Bilal Yavuz wrote:

I think you are right and I confirm that your patch fixes the problem.

Indeed, good catch! I'll go double-check the area before doing
something. Thanks for the report!

Thanks for jumping on this, you beat me to it.

cheers

andrew

--
Andrew Dunstan
EDB: https://www.enterprisedb.com

#5Michael Paquier
michael@paquier.xyz
In reply to: Andrew Dunstan (#4)
Re: Fix jsonpath .split_part() to honor silent mode

On Thu, May 14, 2026 at 08:29:16AM -0400, Andrew Dunstan wrote:

Thanks for jumping on this, you beat me to it.

No problem! I was looking for a different problem to put my mind on,
and was passing by.

I have also checked this whole area of the code for similar trouble,
without finding anything. Nice work overall, from what I've seen.
--
Michael