Don't specify number of dimensions in cases where we don't know it.
authorTom Lane <[email protected]>
Fri, 17 Nov 2023 16:29:42 +0000 (11:29 -0500)
committerTom Lane <[email protected]>
Fri, 17 Nov 2023 16:29:46 +0000 (11:29 -0500)
A few places in array_in() and plperl would report a misleading value
(always MAXDIM+1) for the number of dimensions in the input, because
we'd error out as soon as that was clearly too large rather than
scanning the entire input.  There doesn't seem to be much value in
offering the true number, at least not enough to justify the extra
complication involved in trying to get it.  So just remove that
parenthetical remark.  We already have other places that do it
like that, anyway.

Per suggestions from Alexander Lakhin and Heikki Linnakangas.

Discussion: https://postgr.es/m/2794005.1683042087@sss.pgh.pa.us

src/backend/utils/adt/arrayfuncs.c
src/pl/plperl/expected/plperl_array.out
src/pl/plperl/plperl.c

index d71967de01f0931563db42fe5b9f06cb12880760..631012a0f288320a5e7884d05646e17fa8b86792 100644 (file)
@@ -429,8 +429,8 @@ ReadArrayDimensions(char **srcptr, int *ndim_p, int *dim, int *lBound,
                if (ndim >= MAXDIM)
                        ereturn(escontext, false,
                                        (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
-                                        errmsg("number of array dimensions (%d) exceeds the maximum allowed (%d)",
-                                                       ndim + 1, MAXDIM)));
+                                        errmsg("number of array dimensions exceeds the maximum allowed (%d)",
+                                                       MAXDIM)));
 
                q = p;
                if (!ReadDimensionInt(&p, &i, origStr, escontext))
@@ -641,8 +641,8 @@ ReadArrayStr(char **srcptr,
                                if (nest_level >= MAXDIM)
                                        ereturn(escontext, false,
                                                        (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
-                                                        errmsg("number of array dimensions (%d) exceeds the maximum allowed (%d)",
-                                                                       nest_level + 1, MAXDIM)));
+                                                        errmsg("number of array dimensions exceeds the maximum allowed (%d)",
+                                                                       MAXDIM)));
 
                                nelems[nest_level] = 0;
                                nest_level++;
index bd04a062fb9de4cb293c09972142eaf3ec282b4a..260a55ea7e9b98ec7521198d897a7abefd8a6d47 100644 (file)
@@ -61,7 +61,7 @@ select plperl_sum_array('{{{{{{{1,2},{3,4}},{{5,6},{7,8}}},{{{9,10},{11,12}},
 {{{{{1,2},{3,4}},{{5,6},{7,8}}},{{{9,10},{11,12}},{{13,14},{15,16}}}},
 {{{{17,18},{19,20}},{{21,22},{23,24}}},{{{25,26},{27,28}},{{29,30},{31,32}}}}}}}'
 );
-ERROR:  number of array dimensions (7) exceeds the maximum allowed (6)
+ERROR:  number of array dimensions exceeds the maximum allowed (6)
 LINE 1: select plperl_sum_array('{{{{{{{1,2},{3,4}},{{5,6},{7,8}}},{...
                                 ^
 select plperl_sum_array('{{{1,2,3}, {4,5,6,7}}, {{7,8,9}, {10, 11, 12}}}');
index 863864253f901667b17edd0dd2a4538a6e6bdb8d..d68ad7be34556c3da75608bce51fc4eed02e6fba 100644 (file)
@@ -1201,8 +1201,8 @@ array_to_datum_internal(AV *av, ArrayBuildState **astatep,
                                if (cur_depth + 1 > MAXDIM)
                                        ereport(ERROR,
                                                        (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
-                                                        errmsg("number of array dimensions (%d) exceeds the maximum allowed (%d)",
-                                                                       cur_depth + 1, MAXDIM)));
+                                                        errmsg("number of array dimensions exceeds the maximum allowed (%d)",
+                                                                       MAXDIM)));
                                /* OK, add a dimension */
                                dims[*ndims] = av_len(nav) + 1;
                                (*ndims)++;