Re: Copying data from int column to array column

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Adam Witney <awitney(at)sgul(dot)ac(dot)uk>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Copying data from int column to array column
Date: 2005-06-08 13:19:11
Message-ID: 20050608131911.GA71371@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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/

In response to

Browse pgsql-general by date

  From Date Subject
Next Message John DeSoi 2005-06-08 13:40:33 Re: Where to find translation of Postgres error messages?
Previous Message Richard_D_Levine 2005-06-08 13:18:43 Re: To SPAM or not to SPAM...