pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Richard Huxton <dev@archonet.com>
To: Robert.Farrugia@go.com.mt
Cc: pgsql-sql@postgresql.org
Subject: Re: Inserting values in arrays
Date: Tue, 15 Mar 2005 08:08:46 +0000
Message-ID: <4236980E.3080807@archonet.com> (raw)
In-Reply-To: <OF96764BBA.060DB4E6-ONC1256FC4.0061C3D4-C1256FC4.00623B75@go.com.mt>
References: <OF96764BBA.060DB4E6-ONC1256FC4.0061C3D4-C1256FC4.00623B75@go.com.mt>

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



view thread (3+ messages)  latest in thread

Message-ID: <4236980E.3080807@archonet.com>
Permalink:  ../4236980E.3080807@archonet.com/
Also on:    postgresql.org/message-id/4236980E.3080807@archonet.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: dev@archonet.com, Robert.Farrugia@go.com.mt
  Subject: Re: Inserting values in arrays
  In-Reply-To: <4236980E.3080807@archonet.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox