Re: Inserting values in arrays

From: Robert(dot)Farrugia(at)go(dot)com(dot)mt
To: dev(at)archonet(dot)com
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Inserting values in arrays
Date: 2005-03-15 09:00:14
Message-ID: OF366D0E40.6AA0C914-ONC1256FC5.00313A55-C1256FC5.00317380@go.com.mt
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Richard,

So the solution can be:
(i) either write a function to insert the values into the array
one by one
(ii) or else upgrade to 7.4 (or 8) to use the ARRAY syntax.

Thanks a lot.

Regards
Robert

Richard Huxton <dev(at)archonet(dot)com>
03/15/2005 09:08 AM

To
Robert(dot)Farrugia(at)go(dot)com(dot)mt
cc
pgsql-sql(at)postgresql(dot)org
Subject
Re: [SQL] Inserting values in arrays

Robert(dot)Farrugia(at)go(dot)com(dot)mt wrote:
> CREATE TABLE test ( details varchar[]);
> CREATE TABLE test2 ( textvalue1 varchar, textvalue2 varchar);
> INSERT INTO test2 VALUES ('Hello1', 'World1');
> INSERT INTO test2 VALUES ('hello2', 'World2');

> and I am expecting the following rows in test
> {'Hello1', 'World1'}
> {'Hello2', 'World2'}

> Postgres version I am using is 7.3.4

Well, from 7.4 you can do:

INSERT INTO test SELECT ARRAY[textvalue1, textvalue2] FROM test2;
INSERT 0 2
richardh=> SELECT * FROM test;
details
-----------------
{Hello1,World1}
{hello2,World2}
(2 rows)

I think in 7.3 you might have to write your own function to assemble the
array. I'm not an array expert though, so might be worth checking the
mailing list archives.

--
Richard Huxton
Archonet Ltd

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Christoph Haller 2005-03-15 09:09:04 Re: How to cast VARCHAR to BYTEA and vice-versa?
Previous Message Richard Huxton 2005-03-15 08:18:59 Re: select multiple immediate values, but in multiple rows