Skip site navigation (1) Skip section navigation (2)

Populating an array from a select statement

From: John Gunther <postgresql(at)bucksvsbytes(dot)com>
To:
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Populating an array from a select statement
Date: 2008-02-18 13:22:14
Message-ID: 47B98686.2080109@bucksvsbytes.com (view raw or flat)
Thread:
Lists: pgsql-novice
What's the most straightforward way to populate an array from a select 
statement? For example, using a fictional extension of SQL syntax, I'd like:

update users set emails=ARRAY[select email from address where userid=25] 
where id=25;

So if user 25  has emails john(at)domain(dot)com, john(at)gmail(dot)com, and 
john(at)yahoo(dot)com in the address table,
select emails from user where id=25;
will return:
                                          emails
----------------------------------------------------------------
 {john(at)domain(dot)com, john(at)gmail(dot)com, and john(at)yahoo(dot)com}


If there's no built in way to do this, I'd suggest it as a future feature.

In response to

Responses

pgsql-novice by date

Next:From: A. KretschmerDate: 2008-02-18 13:47:15
Subject: Re: Populating an array from a select statement
Previous:From: Nicholas HemleyDate: 2008-02-18 10:54:30
Subject: postgres 8.3 & ident authentication

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group