Re: array_lower /array_prepend doubt - Mailing list pgsql-sql

From Joe Conway
Subject Re: array_lower /array_prepend doubt
Date
Msg-id 400EBEF0.6060005@joeconway.com
Whole thread Raw
In response to Re: array_lower /array_prepend doubt  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: array_lower /array_prepend doubt
List pgsql-sql
Tom Lane wrote:
> Rajesh Kumar Mallah <mallah@trade-india.com> writes:
>>can anyone explain why
>> SELECT array_lower(array_prepend(0, ARRAY[1,2,3]), 1);
>>returns 0 not 1
> 
> Because array_prepend keeps the subscripts of the existing array
> elements the same.  This was discussed during development of the
> code, but I don't see anything in the documentation that mentions it.
> 

It could perhaps be added to the "Functions and Operators" page for 
arrays, but it is mentioned here:

http://www.postgresql.org/docs/current/static/arrays.html#AEN5183

"When a single element is pushed on to the beginning of a 
one-dimensional array, the result is an array with a lower bound 
subscript equal to the right-hand operand's lower bound subscript, minus 
one. When a single element is pushed on to the end of a one-dimensional 
array, the result is an array retaining the lower bound of the left-hand 
operand. For example:

SELECT array_dims(1 || ARRAY[2,3]);  array_dims ------------  [0:2] (1 row)
 SELECT array_dims(ARRAY[1,2] || 3);  array_dims ------------  [1:3] (1 row)
"

Joe



pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: array_lower /array_prepend doubt
Next
From: Tom Lane
Date:
Subject: Re: array_lower /array_prepend doubt