aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/arrayutils.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2023-11-13 13:01:47 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2023-11-13 13:01:51 -0500
commit83472de606db42a1e1f59ab2c3d0e5ae0b95e739 (patch)
treeb3a27a66a23b266f238ba1dfee535361d4c486cb /src/backend/utils/adt/arrayutils.c
parent57d6a198c9f62c5379cdb6e85e956be2257979c7 (diff)
downloadpostgresql-83472de606db42a1e1f59ab2c3d0e5ae0b95e739.tar.gz
postgresql-83472de606db42a1e1f59ab2c3d0e5ae0b95e739.zip
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
Diffstat (limited to 'src/backend/utils/adt/arrayutils.c')
-rw-r--r--src/backend/utils/adt/arrayutils.c15
1 files changed, 0 insertions, 15 deletions
diff --git a/src/backend/utils/adt/arrayutils.c b/src/backend/utils/adt/arrayutils.c
index aed799234cd..62439715433 100644
--- a/src/backend/utils/adt/arrayutils.c
+++ b/src/backend/utils/adt/arrayutils.c
@@ -44,21 +44,6 @@ ArrayGetOffset(int n, const int *dim, const int *lb, const int *indx)
}
/*
- * Same, but subscripts are assumed 0-based, and use a scale array
- * instead of raw dimension data (see mda_get_prod to create scale array)
- */
-int
-ArrayGetOffset0(int n, const int *tup, const int *scale)
-{
- int i,
- lin = 0;
-
- for (i = 0; i < n; i++)
- lin += tup[i] * scale[i];
- return lin;
-}
-
-/*
* Convert array dimensions into number of elements
*
* This must do overflow checking, since it is used to validate that a user