Commit d0ee9379 authored by Bruce Momjian's avatar Bruce Momjian

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
parent 858ec118
...@@ -425,8 +425,8 @@ ArrayCount(const char *str, int *dim, char typdelim) ...@@ -425,8 +425,8 @@ ArrayCount(const char *str, int *dim, char typdelim)
for (i = 0; i < MAXDIM; ++i) for (i = 0; i < MAXDIM; ++i)
{ {
temp[i] = dim[i] = 0; temp[i] = dim[i] = nelems_last[i] = 0;
nelems_last[i] = nelems[i] = 1; nelems[i] = 1;
} }
ptr = str; ptr = str;
...@@ -540,8 +540,8 @@ ArrayCount(const char *str, int *dim, char typdelim) ...@@ -540,8 +540,8 @@ ArrayCount(const char *str, int *dim, char typdelim)
errmsg("malformed array literal: \"%s\"", str))); errmsg("malformed array literal: \"%s\"", str)));
nest_level--; nest_level--;
if ((nelems_last[nest_level] != 1) && if (nelems_last[nest_level] != 0 &&
(nelems[nest_level] != nelems_last[nest_level])) nelems[nest_level] != nelems_last[nest_level])
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("multidimensional arrays must have " errmsg("multidimensional arrays must have "
......
...@@ -1491,7 +1491,7 @@ select cardinality('{{1,2},{3,4},{5,6}}'::int[]); ...@@ -1491,7 +1491,7 @@ select cardinality('{{1,2},{3,4},{5,6}}'::int[]);
6 6
(1 row) (1 row)
select cardinality('{{{1}},{{2,3},{3,4}}}'::int[]); select cardinality('{{{1,9},{5,6}},{{2,3},{3,4}}}'::int[]);
cardinality cardinality
------------- -------------
8 8
......
...@@ -425,7 +425,7 @@ select cardinality(array[1,2,3]); ...@@ -425,7 +425,7 @@ select cardinality(array[1,2,3]);
select cardinality('[2:4]={5,6,7}'::int[]); select cardinality('[2:4]={5,6,7}'::int[]);
select cardinality('{{1,2}}'::int[]); select cardinality('{{1,2}}'::int[]);
select cardinality('{{1,2},{3,4},{5,6}}'::int[]); select cardinality('{{1,2},{3,4},{5,6}}'::int[]);
select cardinality('{{{1}},{{2,3},{3,4}}}'::int[]); select cardinality('{{{1,9},{5,6}},{{2,3},{3,4}}}'::int[]);
select array_agg(unique1) from (select unique1 from tenk1 where unique1 < 15 order by unique1) ss; select array_agg(unique1) from (select unique1 from tenk1 where unique1 < 15 order by unique1) ss;
select array_agg(ten) from (select ten from tenk1 where unique1 < 15 order by unique1) ss; select array_agg(ten) from (select ten from tenk1 where unique1 < 15 order by unique1) ss;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment