Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1W9cqM-00076x-SR for pgsql-bugs@arkaria.postgresql.org; Sat, 01 Feb 2014 15:50:55 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1W9cqM-0000mr-CX for pgsql-bugs@arkaria.postgresql.org; Sat, 01 Feb 2014 15:50:54 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1W9cqL-0000me-O1 for pgsql-bugs@postgresql.org; Sat, 01 Feb 2014 15:50:53 +0000 Received: from momjian.us ([72.94.173.45]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1W9cqI-0001rH-Op for pgsql-bugs@postgresql.org; Sat, 01 Feb 2014 15:50:53 +0000 Received: from bruce by momjian.us with local (Exim 4.72) (envelope-from ) id 1W9cqB-0003Lm-0g; Sat, 01 Feb 2014 10:50:43 -0500 Date: Sat, 1 Feb 2014 10:50:43 -0500 From: Bruce Momjian To: Joe Conway Cc: borz_off@cs.msu.su, pgsql-bugs@postgresql.org Subject: Re: BUG #8399: inconsistent input of multidimensional arrays Message-ID: <20140201155043.GI31141@momjian.us> References: <20140201011125.GG19957@momjian.us> <52EC51F5.1020701@joeconway.com> <52EC8B04.8050206@joeconway.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="kfjH4zxOES6UT95V" Content-Disposition: inline In-Reply-To: <52EC8B04.8050206@joeconway.com> User-Agent: Mutt/1.5.20 (2009-06-14) X-Pg-Spam-Score: -2.4 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org --kfjH4zxOES6UT95V Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 http://momjian.us EnterpriseDB http://enterprisedb.com + Everyone has their own god. + --kfjH4zxOES6UT95V Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="array.diff" diff --git a/src/backend/utils/adt/arrayfuncs.c b/src/backend/utils/adt/arrayfuncs.c new file mode 100644 index 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.out new file mode 100644 index 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.sql new file mode 100644 index 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; --kfjH4zxOES6UT95V Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs --kfjH4zxOES6UT95V--