Re: proposal: searching in array function - array_position - Mailing list pgsql-hackers

From Pavel Stehule
Subject Re: proposal: searching in array function - array_position
Date
Msg-id CAFj8pRAsDKQtPnMHW+fc-N+gbvxb_Ed1_fXSEAPRgSaY1-Q3hA@mail.gmail.com
Whole thread Raw
In response to Re: proposal: searching in array function - array_position  (Alvaro Herrera <alvherre@2ndquadrant.com>)
List pgsql-hackers


2015-03-20 18:29 GMT+01:00 Alvaro Herrera <alvherre@2ndquadrant.com>:
Pavel Stehule wrote:
> 2015-03-20 17:49 GMT+01:00 Dean Rasheed <dean.a.rasheed@gmail.com>:
>
> > There's an issue when the array's lower bound isn't 1:
> >
> > select array_offset('[2:4]={1,2,3}'::int[], 1);
> >  array_offset
> > --------------
> >             1
> > (1 row)
> >
> > whereas I would expect this to return 2. Similarly for
> > array_offsets(), so the offsets can be used as indexes into the
> > original array.
> >
>
> I am thinking, so it is ok - it returns a offset, not position.

So you can't use it as a subscript?  That sounds unfriendly.  Almost
every function using this will be subtly broken.
 

depends what you want. It means - it is on Nth position from start. So it is useful when iterate over array, because it is safe against different array start dimensions. it works, if you use it as "offset". It is named "array_offset"

It can be changed and renamed to array_position - it is simple fix.  But I am not sure, if it is better.

Regards

Pavel


--
Álvaro Herrera                http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

pgsql-hackers by date:

Previous
From: "Joshua D. Drake"
Date:
Subject: Remove fsync ON/OFF as a visible option?
Next
From: Tom Lane
Date:
Subject: Re: Remove fsync ON/OFF as a visible option?