Re: Fix jsonpath .decimal() to honor silent mode

From: Ewan Young <kdbase(dot)hack(at)gmail(dot)com>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
Subject: Re: Fix jsonpath .decimal() to honor silent mode
Date: 2026-07-01 12:32:05
Message-ID: CAON2xHNbGb8uW4zCH22YivZLE-UNJoQT_a7Eb+usGjh1hDvrmw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Jul 1, 2026 at 6:31 PM Michael Paquier <michael(at)paquier(dot)xyz> wrote:
>
> On Wed, Jul 01, 2026 at 03:52:51PM +0800, Ewan Young wrote:
> > If reviewers would rather push the ErrorSaveContext down into
> > numerictypmodin() (or a shared helper)
> > instead of pre-validating in the caller, I'm happy to reshape it that way.
>
> My first impression while looking at your patch and the surroundings
> of numeric.c is that we should do exactly that, and feed from the
> error message received from the new function to which an escontext is
> given. That would save in extra error messages (why not just reuse
> the same errstrings in this case?), and we could rely on
> error_occurred for the detection.

Agreed, that's nicer -- v2 attached does it that way.

I split numerictypmodin()'s range checks and typmod packing into a new
make_numeric_typmod_safe(precision, scale, escontext) in numeric.c. It
reports an out-of-range precision or scale through the escontext and
returns -1, or throws when escontext is NULL.

- numerictypmodin() calls it with a NULL escontext, so its behavior and
error messages are unchanged.
- .decimal() calls it with its own ErrorSaveContext when not throwing
errors (jspThrowErrors(cxt) ? NULL : &escontext) and relies on
error_occurred. So there are no new message strings, and in the
throwing case the same "NUMERIC precision N must be between 1 and
1000" is raised as before. As a side effect .decimal() no longer
needs to build a cstring array to reach numerictypmodin().

Thanks for the review.

> --
> Michael

--
Regards,
Ewan Young

Attachment Content-Type Size
v2-0001-Fix-jsonpath-decimal-to-honor-silent-mode.patch application/octet-stream 9.6 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Roman Khapov 2026-07-01 12:44:17 Re: DROP INVALID INDEXES command
Previous Message Jacob Champion 2026-07-01 12:28:44 Re: Coverage (lcov) failing with inconsistent error in versions 2.x