Re: How may I keep prepended array items positive? - Mailing list pgsql-general

From Michael Fuhr
Subject Re: How may I keep prepended array items positive?
Date
Msg-id 20051101060340.GA5367@winnie.fuhr.org
Whole thread Raw
In response to How may I keep prepended array items positive?  (Matthew Peter <survivedsushi@yahoo.com>)
Responses Re: How may I keep prepended array items positive?  (Matthew Peter <survivedsushi@yahoo.com>)
List 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

pgsql-general by date:

Previous
From: Erick Papadakis
Date:
Subject: Cpanel and PostgreSQL 8.1rc
Next
From: Matthew Peter
Date:
Subject: Re: How may I keep prepended array items positive?