]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Fix jsonpath .decimal() to honor silent mode
authorMichael Paquier <michael@paquier.xyz>
Thu, 2 Jul 2026 03:44:33 +0000 (12:44 +0900)
committerMichael Paquier <michael@paquier.xyz>
Thu, 2 Jul 2026 03:44:33 +0000 (12:44 +0900)
commit84001a04d552ffd00863a3a9f67f42fc8cb0b677
tree7aaf9b286b5dec915c581f8b68efd8bb0b847033
parent1e1d07792e0827ca84685784c0c958127f5853eb
Fix jsonpath .decimal() to honor silent mode

The jsonpath .decimal(precision[, scale]) method built its numeric
typmod by calling numerictypmodin() through DirectFunctionCall1(), which
can throw a hard error for an incorrect set of precision and/or scale
vaulues.  This breaks the silent mode supported by this function, that
should not fail.

Most of the jsonpath code uses the soft error reporting to bypass
errors, which is what this fix does by avoiding a direct use of
numerictypmodin().  Its code is refactored to use a new routine called
make_numeric_typmod_safe(), able to take an error context in input.
numerictypmodin() sets no context, mapping to its previous behavior.
The jsonpath code sets or not a context depending on the use of the
silent mode.  This result leads to some nice simplifications:
numerictypmodin() feeds on an array, we can now pass directly values for
the scale and precision.

Oversight in 66ea94e8e606.

Author: Ewan Young <kdbase.hack@gmail.com>
Discussion: https://postgr.es/m/CAON2xHMaigKABiyPBBq3Sjd3gp7uWMJXnnMHt=s85V1ij3KP1w@mail.gmail.com
Backpatch-through: 17
src/backend/utils/adt/jsonpath_exec.c
src/backend/utils/adt/numeric.c
src/include/utils/numeric.h
src/test/regress/expected/jsonb_jsonpath.out
src/test/regress/sql/jsonb_jsonpath.sql