Re: Problems with arrays

From: Joe Conway <mail(at)joeconway(dot)com>
To: Harry Broomhall <harry(dot)broomhall(at)uk(dot)easynet(dot)net>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Problems with arrays
Date: 2003-07-07 21:38:42
Message-ID: 3F09E862.4030400@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Harry Broomhall wrote:
>>swipe2test=> create table test_arr (id integer, ratecardlist integer[]);
>>CREATE TABLE
>>swipe2test=> insert into test_arr (id) values (1);
>>INSERT 183981491 1
>>swipe2test=> select * from test_arr;
>> id | ratecardlist
>>----+--------------
>> 1 | (null)
>>(1 row)
>>
>>swipe2test=> update test_arr set ratecardlist[1:3] = '{3,4,5}' where id = 1;
>>UPDATE 1

While perhaps misleading, the answer is correct. You are appending array
elements to a NULL array, so the answer should be null. I think what you
really want here is:

regression=# update test_arr set ratecardlist = '{3,4,5}' where id = 1;
UPDATE 1
regression=# select * from test_arr;
id | ratecardlist
----+--------------
1 | {3,4,5}
(1 row)

This actually replaces the NULL array instead of appending to it.

HTH,

Joe

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Daniel Phlander 2003-07-07 22:22:14 UNSUBSCRIBE
Previous Message scott.marlowe 2003-07-07 19:35:17 Re: Extreme high load averages