Re: Populating an array from a select statement
От | A. Kretschmer |
---|---|
Тема | Re: Populating an array from a select statement |
Дата | |
Msg-id | 20080218134715.GC23570@a-kretschmer.de обсуждение исходный текст |
Ответ на | Populating an array from a select statement (John Gunther <postgresql@bucksvsbytes.com>) |
Ответы |
Re: Populating an array from a select statement
|
Список | pgsql-novice |
am Mon, dem 18.02.2008, um 8:22:14 -0500 mailte John Gunther folgendes: > 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@domain.com, john@gmail.com, and > john@yahoo.com in the address table, > select emails from user where id=25; > will return: > emails > ---------------------------------------------------------------- > {john@domain.com, john@gmail.com, and john@yahoo.com} You can use array_to_string() and array(). Example: test=*# select * from mail_adr ; id | email ----+--------------- 2 | foo@bar 2 | bar@batz 2 | foobar@barfoo (3 rows) test=*# select array_to_string(array(select email from mail_Adr where id=2), ', '); array_to_string ---------------------------------- foo@bar, bar@batz, foobar@barfoo (1 row) Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header) GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net
В списке pgsql-novice по дате отправления: