Fix jsonpath .split_part() to honor silent mode

Chao Li <li.evan.chao@gmail.com>

From: Chao Li <li.evan.chao@gmail.com>
To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Cc: Florents Tselai <florents.tselai@gmail.com>, Andrew Dunstan <andrew@dunslane.net>
Date: 2026-05-12T02:10:53Z
Lists: pgsql-hackers

Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. Fix jsonpath .split_part() to honor silent mode

Attachments

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/