pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Andre Holzner <Andre.Holzner@cern.ch>
Cc: pgsql-sql@postgresql.org
Cc: pgsql-hackers@postgresql.org
Subject: Array slice subscripts (was Re: [SQL] plpgsql function with more than one array argument)
Date: Fri, 01 Feb 2002 16:56:42 -0500
Message-ID: <13301.1012600602@sss.pgh.pa.us> (raw)
In-Reply-To: <3C55E435.280AE10C@cern.ch>
References: <3C55E435.280AE10C@cern.ch>

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



view thread (4+ messages)  latest in thread

Message-ID: <13301.1012600602@sss.pgh.pa.us>
Permalink:  ../13301.1012600602@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/13301.1012600602@sss.pgh.pa.us

 · 

reply

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, Andre.Holzner@cern.ch, pgsql-hackers@postgresql.org
  Subject: Re: Array slice subscripts (was Re: [SQL] plpgsql function with more than one array argument)
  In-Reply-To: <13301.1012600602@sss.pgh.pa.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