Re: How may I keep prepended array items positive?

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Matthew Peter <survivedsushi(at)yahoo(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: How may I keep prepended array items positive?
Date: 2005-11-01 06:03:40
Message-ID: 20051101060340.GA5367@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Oct 31, 2005 at 04:37:39PM -0800, Matthew Peter wrote:
> I would need to prepend a couple array items BUT I
> NEED them to be positive [1:13] instead of [-4:9] for
> instance.
>
> How may I keep prepended array items positive?

You could use array-to-array concatenation instead of prepending
(aka element-to-array concatenation):

test=> SELECT 99 || ARRAY[1, 2, 3]; -- unwanted results
?column?
------------------
[0:3]={99,1,2,3}
(1 row)

test=> SELECT ARRAY[99] || ARRAY[1, 2, 3]; -- desired results
?column?
------------
{99,1,2,3}
(1 row)

--
Michael Fuhr

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Matthew Peter 2005-11-01 06:22:14 Re: How may I keep prepended array items positive?
Previous Message Erick Papadakis 2005-11-01 05:40:01 Cpanel and PostgreSQL 8.1rc