From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Improve readability and error detection of array_in().
Date: Mon, 13 Nov 2023 18:02:07 +0000
Message-ID: <E1r2bGA-005H6H-RX@gemulon.postgresql.org> (raw)
Improve readability and error detection of array_in().
Rewrite array_in() and its subroutines so that we make only one
pass over the input text, rather than two. This requires
potentially re-pallocing the working arrays values[] and nulls[]
larger than our initial guess, but that cost will hopefully be made
up by avoiding duplicate parsing. In any case this coding seems
much clearer and more straightforward than what we had before.
This also fixes array_in() to reject non-rectangular input (that is,
different brace depths in different parts of the input) more reliably
than before, and to give a better error message when it does so.
This is analogous to the plpython and plperl fixes in 0553528e7 and
f47004add. Like those PLs, we now accept input such as '{{},{}}'
as a valid representation of an empty array, which we did not before.
Additionally, reject explicit array subscripts that are outside the
integer range (previously you just got whatever atoi() converted
them to), and make some other minor improvements in error reporting.
Although this is arguably a bug fix, it's also a behavioral change
that might trip somebody up, so no back-patch.
Tom Lane, Heikki Linnakangas, and Jian He. Thanks to Alexander Lakhin
for the initial report and for review/testing.
Discussion: https://postgr.es/m/2794005.1683042087@sss.pgh.pa.us
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/83472de606db42a1e1f59ab2c3d0e5ae0b95e739
Modified Files
--------------
doc/src/sgml/array.sgml | 3 +-
src/backend/utils/adt/arrayfuncs.c | 1185 +++++++++++++++++-----------------
src/backend/utils/adt/arrayutils.c | 15 -
src/include/utils/array.h | 1 -
src/test/regress/expected/arrays.out | 170 ++++-
src/test/regress/sql/arrays.sql | 33 +-
src/tools/pgindent/typedefs.list | 2 +-
7 files changed, 789 insertions(+), 620 deletions(-)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-committers@postgresql.org
Cc: tgl@sss.pgh.pa.us, pgsql-committers@lists.postgresql.org
Subject: Re: pgsql: Improve readability and error detection of array_in().
In-Reply-To: <E1r2bGA-005H6H-RX@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox