BUG: jsonpath .split_part() bypasses lax-mode error suppression

From: SATYANARAYANA NARLAPURAM <satyanarlapuram(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Cc: florents(dot)tselai(at)gmail(dot)com, david(at)justatheory(dot)com
Subject: BUG: jsonpath .split_part() bypasses lax-mode error suppression
Date: 2026-04-18 16:31:03
Message-ID: CAHg+QDfdUG+6OJ5kSxmVim-UJkrtffWByLf4oftxwG7_ySYsDA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi hackers,

The jsonpath string method .split_part() bypasses lax-mode error
suppression.
This is because executeStringInternalMethod() uses
DirectFunctionCall1(numeric_int4, ...)
to convert the field number from numeric to int4. This throws
ereport(ERROR) directly,
bypassing the jspThrowErrors(cxt) / RETURN_ERROR mechanism that other
methods
like .double() use correctly.

Reproduction:
-- These should return NULL in lax mode, but throw hard ERRORs:
SELECT '"hello-world"'::jsonb @? '$.split_part("-", 99999999999)';
SELECT '"hello-world"'::jsonb @? '$.split_part("-", 0)';
ERROR: integer out of range
ERROR: field position must not be zero

Fix by replacing the bare DirectFunctionCall with numeric_int4_safe()
using ErrorSaveContext to catch overflow, and adding an explicit field==0
check, both gated behind RETURN_ERROR so errors are properly suppressed
in lax/silent mode while still raised in strict/non-silent mode.

Thanks,
Satya

Attachment Content-Type Size
0001-Fix-jsonpath-.split_part-to-respect-error-suppressio.patch application/octet-stream 6.2 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2026-04-18 16:33:26 Re: eliminate xl_heap_visible to reduce WAL (and eventually set VM on-access)
Previous Message Andres Freund 2026-04-18 16:25:48 Re: eliminate xl_heap_visible to reduce WAL (and eventually set VM on-access)