Fix jsonpath .split_part() to honor silent mode

From: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Cc: Florents Tselai <florents(dot)tselai(at)gmail(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>
Subject: Fix jsonpath .split_part() to honor silent mode
Date: 2026-05-12 02:10:53
Message-ID: FCF996D0-580B-431C-8DE1-A540C58E444C@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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 Content-Type Size
v1-0001-Fix-jsonpath-.split_part-to-honor-silent-mode.patch application/octet-stream 4.7 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Hayato Kuroda (Fujitsu) 2026-05-12 02:25:47 RE: Adding REPACK [concurrently]
Previous Message Peter Smith 2026-05-12 02:02:36 Re: pg_createsubscriber: Fix incorrect handling of cleanup flags