Re: Inserting values in arrays - Mailing list pgsql-sql

From Richard Huxton
Subject Re: Inserting values in arrays
Date
Msg-id 4236980E.3080807@archonet.com
Whole thread Raw
In response to Inserting values in arrays  (Robert.Farrugia@go.com.mt)
Responses Re: Inserting values in arrays  (Robert.Farrugia@go.com.mt)
List pgsql-sql
Robert.Farrugia@go.com.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


pgsql-sql by date:

Previous
From: Luca Pireddu
Date:
Subject: select multiple immediate values, but in multiple rows
Next
From: Richard Huxton
Date:
Subject: Re: select multiple immediate values, but in multiple rows