Re: array variables - Mailing list pgsql-sql

From Tom Lane
Subject Re: array variables
Date
Msg-id 3947.1226582056@sss.pgh.pa.us
Whole thread Raw
In response to Re: array variables  ("Pavel Stehule" <pavel.stehule@gmail.com>)
Responses Re: array variables
List pgsql-sql
"Pavel Stehule" <pavel.stehule@gmail.com> writes:
> 2008/11/13 Marcin Krawczyk <jankes.mk@gmail.com>:
>> Because if I try this :
>> a := ARRAY(SELECT id, p FROM idx);
>> I get
>> ERROR: subquery must return only one column

> you can't do it directly :( now.

Sure you can, if you're using a version new enough to have arrays of
composite types.

regression=# create table t1 (f1 int, f2 text);
CREATE TABLE
regression=# insert into t1 values (1,'one');
INSERT 0 1
regression=# insert into t1 values (2,'two');
INSERT 0 1
regression=# select array(select row(t1.*)::t1 from t1);      ?column?        
-----------------------{"(1,one)","(2,two)"}
(1 row)

Whether this is a good idea for a large table is a different question ;-)
        regards, tom lane


pgsql-sql by date:

Previous
From: Achilleas Mantzios
Date:
Subject: Re: array variables
Next
From: "Pavel Stehule"
Date:
Subject: Re: array variables