Array slice subscripts (was Re: plpgsql function with more than one array argument) - Mailing list pgsql-sql

From Tom Lane
Subject Array slice subscripts (was Re: plpgsql function with more than one array argument)
Date
Msg-id 13301.1012600602@sss.pgh.pa.us
Whole thread Raw
In response to plpgsql function with more than one array argument  (Andre Holzner <Andre.Holzner@cern.ch>)
Responses Re: [HACKERS] Array slice subscripts (was Re: plpgsql function  (Bruce Momjian <pgman@candle.pha.pa.us>)
List pgsql-sql
Andre Holzner <Andre.Holzner@cern.ch> 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


pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: NOTICE: Vacuum: can not process indices, views and certain system tables
Next
From: pocm@rnl.ist.utl.pt (Paulo J. Matos)
Date:
Subject: Fractional Results