X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 27547564A6 for ; Tue, 15 Mar 2005 08:09:08 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 43054-10 for ; Tue, 15 Mar 2005 08:08:57 +0000 (GMT) Received: from anchor-post-33.mail.demon.net (anchor-post-33.mail.demon.net [194.217.242.91]) by svr1.postgresql.org (Postfix) with ESMTP id 669F5564A7 for ; Tue, 15 Mar 2005 08:08:52 +0000 (GMT) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-33.mail.demon.net with esmtp (Exim 4.42) id 1DB76f-0001Dw-Af; Tue, 15 Mar 2005 08:08:49 +0000 Received: from [192.168.1.17] (client17.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id EEBFA17604; Tue, 15 Mar 2005 08:08:47 +0000 (GMT) Message-ID: <4236980E.3080807@archonet.com> Date: Tue, 15 Mar 2005 08:08:46 +0000 From: Richard Huxton User-Agent: Mozilla Thunderbird 1.0 (X11/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Robert.Farrugia@go.com.mt Cc: pgsql-sql@postgresql.org Subject: Re: Inserting values in arrays References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.062 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200503/209 X-Sequence-Number: 20688 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