pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Array slice subscripts (was Re: [SQL] plpgsql function with more than one array argument)
4+ messages / 3 participants
[nested] [flat]

* Array slice subscripts (was Re: [SQL] plpgsql function with more than one array argument)
@ 2002-02-01 21:56  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 4+ messages in thread

From: Tom Lane @ 2002-02-01 21:56 UTC (permalink / raw)
  To: Andre Holzner <Andre.Holzner@cern.ch>; +Cc: pgsql-sql; pgsql-hackers@postgresql.org

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



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Array slice subscripts (was Re: [SQL] plpgsql function
@ 2002-02-22 03:55  Bruce Momjian <pgman@candle.pha.pa.us>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 4+ messages in thread

From: Bruce Momjian @ 2002-02-22 03:55 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Andre Holzner <Andre.Holzner@cern.ch>; pgsql-sql; pgsql-hackers@postgresql.org


Is this a TODO item?

---------------------------------------------------------------------------

Tom Lane wrote:
> 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
> 
> ---------------------------(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



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Array slice subscripts (was Re: [SQL] plpgsql function with more than one array argument)
@ 2002-02-22 04:14  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Bruce Momjian <pgman@candle.pha.pa.us>
  0 siblings, 1 reply; 4+ messages in thread

From: Tom Lane @ 2002-02-22 04:14 UTC (permalink / raw)
  To: Bruce Momjian <pgman@candle.pha.pa.us>; +Cc: Andre Holzner <Andre.Holzner@cern.ch>; pgsql-sql; pgsql-hackers@postgresql.org

Bruce Momjian <pgman@candle.pha.pa.us> writes:
> Is this a TODO item?

I guess so, since no one seems to have objected to the proposed change.
It's a pretty trivial change; I'll take care of it.

			regards, tom lane

> Tom Lane wrote:
>> 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



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Array slice subscripts (was Re: [SQL] plpgsql function
@ 2002-02-22 09:17  Andre Holzner <Andre.Holzner@cern.ch>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 4+ messages in thread

From: Andre Holzner @ 2002-02-22 09:17 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Bruce Momjian <pgman@candle.pha.pa.us>; pgsql-hackers@postgresql.org

Hello developpers,

Tom Lane wrote:
> 
> Bruce Momjian <pgman@candle.pha.pa.us> writes:
> > Is this a TODO item?
> 
> I guess so, since no one seems to have objected to the proposed change.
> It's a pretty trivial change; I'll take care of it.
> 
>                         regards, tom lane

I learned to live without it, but I wont be the last one 
who tries to use such queries.


best regards & thanks a lot for your efforts,

André


> 
> > Tom Lane wrote:
> >> 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

-- 
------------------+----------------------------------
Andre Holzner     | +41 22 76 76750 
Bureau 32 2-C13   | Building 32     
CERN              | Office 2-C13    
CH-1211 Geneve 23 | http://wwweth.cern.ch/~holzner/



^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2002-02-22 09:17 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-02-01 21:56 Array slice subscripts (was Re: [SQL] plpgsql function with more than one array argument) Tom Lane <tgl@sss.pgh.pa.us>
2002-02-22 03:55 ` Re: Array slice subscripts (was Re: [SQL] plpgsql function Bruce Momjian <pgman@candle.pha.pa.us>
2002-02-22 04:14   ` Tom Lane <tgl@sss.pgh.pa.us>
2002-02-22 09:17     ` Re: Array slice subscripts (was Re: [SQL] plpgsql function Andre Holzner <Andre.Holzner@cern.ch>

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