Re: how can I select into an array? - Mailing list pgsql-general

From Tom Lane
Subject Re: how can I select into an array?
Date
Msg-id 1213.1076087296@sss.pgh.pa.us
Whole thread Raw
In response to how can I select into an array?  ("Andy Kriger" <akriger@greaterthanone.com>)
Responses Re: how can I select into an array?  (elein <elein@varlena.com>)
List pgsql-general
"Andy Kriger" <akriger@greaterthanone.com> writes:
> I would like to select strings from a table and return them as an array

You can do that beginning in 7.4 with the ARRAY(sub-select) construct.

regression=# select f1 from text_tbl;
        f1
-------------------
 doh!
 hi de ho neighbor
(2 rows)

regression=# select array(select f1 from text_tbl);
          ?column?
----------------------------
 {doh!,"hi de ho neighbor"}
(1 row)

regression=#

In prior versions you could probably fake it with a loop in a plpgsql
function, but it'd be kinda awkward.

            regards, tom lane

pgsql-general by date:

Previous
From: Christoffer Gurell
Date:
Subject: retrieving parts of a resultset
Next
From: Joe Conway
Date:
Subject: Re: Casting 'record' to a composite type.