pgsql: Adjust populate_record_field() to handle errors softly

From: Amit Langote <amitlan(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Adjust populate_record_field() to handle errors softly
Date: 2024-01-24 06:21:50
Message-ID: E1rSWdy-002qPU-96@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Adjust populate_record_field() to handle errors softly

This adds a Node *escontext parameter to it and a bunch of functions
downstream to it, replacing any ereport()s in that path by either
errsave() or ereturn() as appropriate. This also adds code to those
functions where necessary to return early upon encountering a soft
error.

The changes here are mainly intended to suppress errors in the
functions of jsonfuncs.c. Functions in any external modules, such as
arrayfuncs.c, that those functions may in turn call are not changed
here based on the assumption that the various checks in jsonfuncs.c
functions should ensure that only values that are structurally valid
get passed to the functions in those external modules. An exception
is made for domain_check() to allow handling domain constraint
violation errors softly.

For testing, this adds a function jsonb_populate_record_valid(),
which returns true if jsonb_populate_record() would finish without
causing an error for the provided JSON object, false otherwise. Note
that jsonb_populate_record() internally calls populate_record(),
which in turn uses populate_record_field().

Extracted from a much larger patch to add SQL/JSON query functions.

Author: Nikita Glukhov <n(dot)gluhov(at)postgrespro(dot)ru>
Author: Teodor Sigaev <teodor(at)sigaev(dot)ru>
Author: Oleg Bartunov <obartunov(at)gmail(dot)com>
Author: Alexander Korotkov <aekorotkov(at)gmail(dot)com>
Author: Andrew Dunstan <andrew(at)dunslane(dot)net>
Author: Amit Langote <amitlangote09(at)gmail(dot)com>

Reviewers have included (in no particular order) Andres Freund,
Alexander Korotkov, Pavel Stehule, Andrew Alsup, Erik Rijkers,
Zihong Yu, Himanshu Upadhyaya, Daniel Gustafsson, Justin Pryzby,
Álvaro Herrera, Jian He, Peter Eisentraut

Discussion: https://postgr.es/m/cd0bb935-0158-78a7-08b5-904886deac4b@postgrespro.ru
Discussion: https://postgr.es/m/20220616233130.rparivafipt6doj3@alap3.anarazel.de
Discussion: https://postgr.es/m/abd9b83b-aa66-f230-3d6d-734817f0995d%40postgresql.org
Discussion: https://postgr.es/m/CA+HiwqHROpf9e644D8BRqYvaAPmgBZVup-xKMDPk-nd4EpgzHw@mail.gmail.com
Discussion: https://postgr.es/m/CA+HiwqE4XTdfb1nW=Ojoy_tQSRhYt-q_kb6i5d4xcKyrLC1Nbg@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/1edb3b491bee373bdfcbfc1c2707b5428c2023b9

Modified Files
--------------
doc/src/sgml/func.sgml | 52 ++++++
src/backend/utils/adt/domains.c | 33 +++-
src/backend/utils/adt/jsonfuncs.c | 364 +++++++++++++++++++++++++++---------
src/include/catalog/pg_proc.dat | 4 +
src/include/utils/builtins.h | 3 +
src/test/regress/expected/jsonb.out | 115 ++++++++++++
src/test/regress/sql/jsonb.sql | 37 ++++
7 files changed, 521 insertions(+), 87 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Michael Paquier 2024-01-24 07:55:38 pgsql: pgbench: Add \syncpipeline
Previous Message Amit Langote 2024-01-24 06:16:30 pgsql: Add soft error handling to some expression nodes