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 <[email protected]>
Discussion: 
https://postgr.es/m/CAON2xHMaigKABiyPBBq3Sjd3gp7uWMJXnnMHt=s85v1ij3k...@mail.gmail.com
Backpatch-through: 17

Branch
------
REL_17_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/ab35b8d2528641efd4b23111874665c92e7f6b65

Modified Files
--------------
src/backend/utils/adt/jsonpath_exec.c        | 24 ++++-----------
src/backend/utils/adt/numeric.c              | 44 ++++++++++++++++------------
src/include/utils/numeric.h                  |  5 ++++
src/test/regress/expected/jsonb_jsonpath.out | 32 ++++++++++++++++++++
src/test/regress/sql/jsonb_jsonpath.sql      |  7 +++++
5 files changed, 75 insertions(+), 37 deletions(-)

Reply via email to