Received: from candle.pha.pa.us (216-55-132-35.dsl.san-diego.abac.net [216.55.132.35]) by postgresql.org (Postfix) with ESMTP id A59B4475AE8; Thu, 21 Feb 2002 22:56:02 -0500 (EST) Received: (from pgman@localhost) by candle.pha.pa.us (8.11.6/8.10.1) id g1M3ttr13214; Thu, 21 Feb 2002 22:55:55 -0500 (EST) From: Bruce Momjian Message-Id: <200202220355.g1M3ttr13214@candle.pha.pa.us> Subject: Re: Array slice subscripts (was Re: [SQL] plpgsql function In-Reply-To: <13301.1012600602@sss.pgh.pa.us> To: Tom Lane Date: Thu, 21 Feb 2002 22:55:55 -0500 (EST) Cc: Andre Holzner , pgsql-sql@postgresql.org, pgsql-hackers@postgresql.org X-Mailer: ELM [version 2.4ME+ PL96 (25)] MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII X-Archive-Number: 200202/830 X-Sequence-Number: 19115 Is this a TODO item? --------------------------------------------------------------------------- Tom Lane wrote: > Andre Holzner writes: > > Am I doing something wrong or is this a 'feature' ? > > What's biting you is that the array slice operator uses the provided > lower bounds in the resultant array. For example: > > regression=# select pcha from zdec_bhab; > pcha > ------------------------------------ > {{11,12,13},{21,22,23},{31,32,33}} > (1 row) > > regression=# select array_dims(pcha) from zdec_bhab; > array_dims > ------------ > [1:3][1:3] > (1 row) > > regression=# select pcha[2:2][1:3] from zdec_bhab; > pcha > -------------- > {{21,22,23}} > (1 row) > > regression=# select array_dims(pcha[2:2][1:3]) from zdec_bhab; > array_dims > ------------ > [2:2][1:3] > (1 row) > > So your function receives an array with first index starting at 2, > which it's not expecting; its attempt to fetch element [1][1] is out > of bounds and produces a NULL. > > Offhand this behavior seems like a misfeature: perhaps it'd be more > sensible for the extracted slice to always have index lower bounds > set to 1. But I'd like to see some discussion before changing it > (and I don't plan to touch it before 7.2 release, in any case ;-)). > > Comments anyone? > > regards, tom lane > > ---------------------------(end of broadcast)--------------------------- > TIP 5: Have you checked our extensive FAQ? > > http://www.postgresql.org/users-lounge/docs/faq.html > -- Bruce Momjian | http://candle.pha.pa.us pgman@candle.pha.pa.us | (610) 853-3000 + If your life is a hard drive, | 830 Blythe Avenue + Christ can be your backup. | Drexel Hill, Pennsylvania 19026