On Wed, Jul 1, 2026 at 6:31 PM Michael Paquier <michael@paquier.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