Re: Can I reset the lower bound of an array. - Mailing list pgsql-general

From Mark Gibson
Subject Re: Can I reset the lower bound of an array.
Date
Msg-id 40854D0B.6000005@cromwell.co.uk
Whole thread Raw
In response to Can I reset the lower bound of an array.  (Mark Gibson <gibsonm@cromwell.co.uk>)
Responses Re: Can I reset the lower bound of an array.
List pgsql-general
Mark Gibson wrote:

> b) resetting the lower bound of the array (without affecting elements)?
>    eg: set_array_lower(1 || ARRAY[2,3,4], 1) -- 2nd arg is the new
> lower bound


After a bit more playing about, i've discovered a kludgy work-around for
resetting an array's lower bound to 1.

To demonstrate:

 > SELECT array_lower(1 || ARRAY[2,3,4], 1);
 array_lower
-------------
           0

 > SELECT array_lower((1 || ARRAY[2,3,4])[-100:100], 1);
 array_lower
-------------
           1

A slice always has a lower bound of 1, so using a slice that extends well
beyond the bounds of the array will return the array with its lower bound
set at 1.

--
Mark Gibson <gibsonm |AT| cromwell |DOT| co |DOT| uk>
Web Developer & Database Admin
Cromwell Tools Ltd.
Leicester, England.


pgsql-general by date:

Previous
From: Mark Gibson
Date:
Subject: Re: convert result to uppercase
Next
From: jseymour@LinxNet.com (Jim Seymour)
Date:
Subject: Re: [OT] Tom's/Marc's spam filters?