From: Bruce Momjian <bruce@momjian.us>
To: Joe Conway <mail@joeconway.com>
Cc: borz_off@cs.msu.su
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #8399: inconsistent input of multidimensional arrays
Date: Sat, 1 Feb 2014 10:50:43 -0500
Message-ID: <20140201155043.GI31141@momjian.us> (raw)
In-Reply-To: <52EC8B04.8050206@joeconway.com>
References: <E1VEETa-0007KM-8O@wrigleys.postgresql.org>
<20140201011125.GG19957@momjian.us>
<52EC51F5.1020701@joeconway.com>
<52EC8B04.8050206@joeconway.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
On Fri, Jan 31, 2014 at 09:49:56PM -0800, Joe Conway wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On 01/31/2014 05:46 PM, Joe Conway wrote:
> > On 01/31/2014 05:11 PM, Bruce Momjian wrote:
> >> Joe, does this sound right?
>
> > Let me take a closer look...
>
> I had forgotten how convoluted the array code is ;-)
>
> Yes, it looks correct to me, although I think I would initialize
> nelems_last[i] to 0 rather than -1.
Thanks for the review. I went with zero as you suggested. Applied
patch attached.
--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com
+ Everyone has their own god. +
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugsAttachments:array.diff (text/x-diff, 2.9K) downloaddiff --git a/src/backend/utils/adt/arrayfuncs.c b/src/backend/utils/adt/arrayfuncs.cnew file mode 100644index 311d0c2..91df184
*** a/src/backend/utils/adt/arrayfuncs.c
--- b/src/backend/utils/adt/arrayfuncs.c
*************** ArrayCount(const char *str, int *dim, ch
*** 425,432 ****
for (i = 0; i < MAXDIM; ++i)
{
! temp[i] = dim[i] = 0;
! nelems_last[i] = nelems[i] = 1;
}
ptr = str;
--- 425,432 ----
for (i = 0; i < MAXDIM; ++i)
{
! temp[i] = dim[i] = nelems_last[i] = 0;
! nelems[i] = 1;
}
ptr = str;
*************** ArrayCount(const char *str, int *dim, ch
*** 540,547 ****
errmsg("malformed array literal: \"%s\"", str)));
nest_level--;
! if ((nelems_last[nest_level] != 1) &&
! (nelems[nest_level] != nelems_last[nest_level]))
ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("multidimensional arrays must have "
--- 540,547 ----
errmsg("malformed array literal: \"%s\"", str)));
nest_level--;
! if (nelems_last[nest_level] != 0 &&
! nelems[nest_level] != nelems_last[nest_level])
ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("multidimensional arrays must have "
diff --git a/src/test/regress/expected/arrays.out b/src/test/regress/expected/arrays.outnew file mode 100644index e1b9d7f..6dce5c9
*** a/src/test/regress/expected/arrays.out
--- b/src/test/regress/expected/arrays.out
*************** select cardinality('{{1,2},{3,4},{5,6}}'
*** 1491,1497 ****
6
(1 row)
! select cardinality('{{{1}},{{2,3},{3,4}}}'::int[]);
cardinality
-------------
8
--- 1491,1497 ----
6
(1 row)
! select cardinality('{{{1,9},{5,6}},{{2,3},{3,4}}}'::int[]);
cardinality
-------------
8
diff --git a/src/test/regress/sql/arrays.sql b/src/test/regress/sql/arrays.sqlnew file mode 100644index 64630d9..92af172
*** a/src/test/regress/sql/arrays.sql
--- b/src/test/regress/sql/arrays.sql
*************** select cardinality(array[1,2,3]);
*** 425,431 ****
select cardinality('[2:4]={5,6,7}'::int[]);
select cardinality('{{1,2}}'::int[]);
select cardinality('{{1,2},{3,4},{5,6}}'::int[]);
! select cardinality('{{{1}},{{2,3},{3,4}}}'::int[]);
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;
--- 425,431 ----
select cardinality('[2:4]={5,6,7}'::int[]);
select cardinality('{{1,2}}'::int[]);
select cardinality('{{1,2},{3,4},{5,6}}'::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(ten) from (select ten from tenk1 where unique1 < 15 order by unique1) ss;
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: bruce@momjian.us, mail@joeconway.com, borz_off@cs.msu.su
Subject: Re: BUG #8399: inconsistent input of multidimensional arrays
In-Reply-To: <20140201155043.GI31141@momjian.us>
References: <E1VEETa-0007KM-8O@wrigleys.postgresql.org> <20140201011125.GG19957@momjian.us> <52EC51F5.1020701@joeconway.com> <52EC8B04.8050206@joeconway.com> <20140201155043.GI31141@momjian.us>
* 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