Skip to content

Commit d0ee937

Browse files
committed
arrays: tighten checks for multi-dimensional input
Previously an input array string that started with a single-element array dimension would then later accept a multi-dimensional segment. BACKWARD INCOMPATIBILITY
1 parent 858ec11 commit d0ee937

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

src/backend/utils/adt/arrayfuncs.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,8 @@ ArrayCount(const char *str, int *dim, char typdelim)
425425

426426
for (i = 0; i < MAXDIM; ++i)
427427
{
428-
temp[i] = dim[i] = 0;
429-
nelems_last[i] = nelems[i] = 1;
428+
temp[i] = dim[i] = nelems_last[i] = 0;
429+
nelems[i] = 1;
430430
}
431431

432432
ptr = str;
@@ -540,8 +540,8 @@ ArrayCount(const char *str, int *dim, char typdelim)
540540
errmsg("malformed array literal: \"%s\"", str)));
541541
nest_level--;
542542

543-
if ((nelems_last[nest_level] != 1) &&
544-
(nelems[nest_level] != nelems_last[nest_level]))
543+
if (nelems_last[nest_level] != 0 &&
544+
nelems[nest_level] != nelems_last[nest_level])
545545
ereport(ERROR,
546546
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
547547
errmsg("multidimensional arrays must have "

src/test/regress/expected/arrays.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1491,7 +1491,7 @@ select cardinality('{{1,2},{3,4},{5,6}}'::int[]);
14911491
6
14921492
(1 row)
14931493

1494-
select cardinality('{{{1}},{{2,3},{3,4}}}'::int[]);
1494+
select cardinality('{{{1,9},{5,6}},{{2,3},{3,4}}}'::int[]);
14951495
cardinality
14961496
-------------
14971497
8

src/test/regress/sql/arrays.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ select cardinality(array[1,2,3]);
425425
select cardinality('[2:4]={5,6,7}'::int[]);
426426
select cardinality('{{1,2}}'::int[]);
427427
select cardinality('{{1,2},{3,4},{5,6}}'::int[]);
428-
select cardinality('{{{1}},{{2,3},{3,4}}}'::int[]);
428+
select cardinality('{{{1,9},{5,6}},{{2,3},{3,4}}}'::int[]);
429429

430430
select array_agg(unique1) from (select unique1 from tenk1 where unique1 < 15 order by unique1) ss;
431431
select array_agg(ten) from (select ten from tenk1 where unique1 < 15 order by unique1) ss;

0 commit comments

Comments
 (0)