Re: Can I reset the lower bound of an array.

From: Mark Gibson <gibsonm(at)cromwell(dot)co(dot)uk>
To: pgsql <pgsql-general(at)postgresql(dot)org>
Subject: Re: Can I reset the lower bound of an array.
Date: 2004-04-20 16:17:15
Message-ID: 40854D0B.6000005@cromwell.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Mark Gibson 2004-04-20 16:20:21 Re: convert result to uppercase
Previous Message Jan Wieck 2004-04-20 16:00:01 Slony-I heading for release