Re: array_lower /array_prepend doubt

From: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
To: Rajesh Kumar Mallah <mallah(at)trade-india(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: array_lower /array_prepend doubt
Date: 2004-01-21 15:53:11
Message-ID: 20040121074533.J95018@megazone.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


On Wed, 21 Jan 2004, Rajesh Kumar Mallah wrote:

> can anyone explain why
> SELECT array_lower(array_prepend(0, ARRAY[1,2,3]), 1);
> returns 0 not 1
>
> because
>
> tradein_clients=# SELECT array_prepend(0, ARRAY[1,2,3]);
> +---------------+
> | array_prepend |
> +---------------+
> | {0,1,2,3} |
> +---------------+
> (1 row)

It looks like array_prepend is basically inserting the new value at the
index before the start of the array, so 0 is the lower bound. This means
that array_prepend(0,ARRAY[1,2,3]) is not the same array as
ARRAY[0,1,2,3]. If you stick both in a table, and select col[1], in one
you appear to get back 1, in the other 0. However, I think there is a bug
here somewhere, because the former array does not appear to dump/restore
as the same value (both seem to dump as (0,1,2,3})

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2004-01-21 17:14:30 Re: array_lower /array_prepend doubt
Previous Message Rajesh Kumar Mallah 2004-01-21 14:00:12 array_lower /array_prepend doubt