Skip site navigation (1) Skip section navigation (2)

Re: array_lower /array_prepend doubt

From: Joe Conway <mail(at)joeconway(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Rajesh Kumar Mallah <mallah(at)trade-india(dot)com>,pgsql-sql(at)postgresql(dot)org
Subject: Re: array_lower /array_prepend doubt
Date: 2004-01-21 18:03:28
Message-ID: 400EBEF0.6060005@joeconway.com (view raw or flat)
Thread:
Lists: pgsql-sql
Tom Lane wrote:
> Rajesh Kumar Mallah <mallah(at)trade-india(dot)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


In response to

Responses

pgsql-sql by date

Next:From: Tom LaneDate: 2004-01-21 18:11:38
Subject: Re: array_lower /array_prepend doubt
Previous:From: Tom LaneDate: 2004-01-21 17:14:30
Subject: Re: array_lower /array_prepend doubt

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group