public inbox for [email protected]  
help / color / mirror / Atom feed
From: Dmitry Dolgov <[email protected]>
To: SATYANARAYANA NARLAPURAM <[email protected]>
Cc: PostgreSQL Hackers <[email protected]>
Cc: [email protected]
Cc: [email protected]
Subject: Re: BUG: jsonpath .split_part() bypasses lax-mode error suppression
Date: Sun, 19 Apr 2026 22:21:07 +0200
Message-ID: <2cqv3uotlvjsjkkjganonpbghopgjwqqrwwylujmqu3qca7asn@smj4ghtqigpi> (raw)
In-Reply-To: <CAHg+QDfdUG+6OJ5kSxmVim-UJkrtffWByLf4oftxwG7_ySYsDA@mail.gmail.com>
References: <CAHg+QDfdUG+6OJ5kSxmVim-UJkrtffWByLf4oftxwG7_ySYsDA@mail.gmail.com>

> On Sat, Apr 18, 2026 at 09:31:03AM -0700, SATYANARAYANA NARLAPURAM wrote:
> 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

I don't have a SQL standard at hands, it might be worth checking what SQL/JSON
says about such situations. But at least from the definition of lax mode, given
in the documentation, current behavior seems to be correct:

	lax (default) &mdash; the path engine implicitly adapts the queried data to
	the specified path. Any structural errors that cannot be fixed as described
	below are suppressed, producing no match.

I.e. only structural errors are suppressed, where a structural error defined as:

	An attempt to access a non-existent member of an object or element of an
	array is defined as a structural error.

In this case what we have is an error, which happens due to an incorrect
function argument valye (the second argument of split_part, either out of
integer bound, or zero for 1 based field counting). It has nothing to do with
the jsonb document, and hence doesn't fall into "structural errors" category.





view thread (2+ messages)

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected], [email protected], [email protected]
  Subject: Re: BUG: jsonpath .split_part() bypasses lax-mode error suppression
  In-Reply-To: <2cqv3uotlvjsjkkjganonpbghopgjwqqrwwylujmqu3qca7asn@smj4ghtqigpi>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox