pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Joe Conway <mail@joeconway.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Rajesh Kumar Mallah <mallah@trade-india.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: array_lower /array_prepend doubt
Date: Wed, 21 Jan 2004 10:03:28 -0800
Message-ID: <400EBEF0.6060005@joeconway.com> (raw)
In-Reply-To: <1648.1074705270@sss.pgh.pa.us>
References: <400E85EC.4000106@trade-india.com>
	<1648.1074705270@sss.pgh.pa.us>

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




view thread (12+ messages)  latest in thread

Message-ID: <400EBEF0.6060005@joeconway.com>
Permalink:  ../400EBEF0.6060005@joeconway.com/
Also on:    postgresql.org/message-id/400EBEF0.6060005@joeconway.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: mail@joeconway.com, tgl@sss.pgh.pa.us, mallah@trade-india.com
  Subject: Re: array_lower /array_prepend doubt
  In-Reply-To: <400EBEF0.6060005@joeconway.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox