Re: Copying data from int column to array column - Mailing list pgsql-general

From Michael Fuhr
Subject Re: Copying data from int column to array column
Date
Msg-id 20050608131911.GA71371@winnie.fuhr.org
Whole thread Raw
In response to Copying data from int column to array column  (Adam Witney <awitney@sgul.ac.uk>)
List pgsql-general
On Wed, Jun 08, 2005 at 01:21:19PM +0100, Adam Witney wrote:
>
> UPDATE test SET field3[1] = field1;
>
> Why does the UPDATE of field2 work, but the UPDATE of field3 does not?

What version of PostgreSQL are you using?  The example should work
in 8.x.  See the Release Notes:

http://www.postgresql.org/docs/8.0/static/release-8-0.html

"Updating an element or slice of a NULL array value now produces a
non-NULL array result, namely an array containing just the assigned-to
positions."

In previous versions you can get around the problem by first setting
the column to an empty array:

UPDATE test SET field3 = '{}' WHERE field3 IS NULL;
UPDATE test SET field3[1] = field1;

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

pgsql-general by date:

Previous
From: Együd Csaba
Date:
Subject: Re: Where to find translation of Postgres error messages?
Next
From: Richard_D_Levine@raytheon.com
Date:
Subject: Re: To SPAM or not to SPAM...