Received: from sss.pgh.pa.us ([192.204.191.242]) by postgresql.org (8.11.3/8.11.4) with ESMTP id g11Lv0l80683; Fri, 1 Feb 2002 16:57:00 -0500 (EST) (envelope-from tgl@sss.pgh.pa.us) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.11.4/8.11.4) with ESMTP id g11Lugf13304; Fri, 1 Feb 2002 16:56:42 -0500 (EST) To: Andre Holzner cc: pgsql-sql@postgresql.org, pgsql-hackers@postgresql.org Subject: Array slice subscripts (was Re: [SQL] plpgsql function with more than one array argument) In-reply-to: <3C55E435.280AE10C@cern.ch> References: <3C55E435.280AE10C@cern.ch> Comments: In-reply-to Andre Holzner message dated "Tue, 29 Jan 2002 00:52:21 +0100" Date: Fri, 01 Feb 2002 16:56:42 -0500 Message-ID: <13301.1012600602@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200202/58 X-Sequence-Number: 18400 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