Re: array variables - Mailing list pgsql-sql

From Pavel Stehule
Subject Re: array variables
Date
Msg-id 162867790811130130l3ff2bfdcl33748352858f40e1@mail.gmail.com
Whole thread Raw
In response to Re: array variables  ("Marcin Krawczyk" <jankes.mk@gmail.com>)
Responses Re: array variables
List pgsql-sql
Hello

2008/11/13 Marcin Krawczyk <jankes.mk@gmail.com>:
> I know I can do one column like this :
>
> a := ARRAY(SELECT id FROM idx);
>
> but how about more than one ?
> Because if I try this :
>
> a := ARRAY(SELECT id, p FROM idx);
>
> I get
> ERROR: subquery must return only one column
> SQL state: 42601
>

you can't do it directly :( now.

postgres=# create or replace function accum() returns int[] as
$$declare s int[] = '{}'; r record; begin for r in select * from f2
loop s := s || array[[r.a, r.b]]; end loop; return s; end;$$ language
plpgsql;
\CREATE FUNCTION
postgres=# select accum();      accum
-------------------{{10,10},{20,20}}
(1 row)

postgres=# select * from f2;a  | b
----+----10 | 1020 | 20
(2 rows)

regards
Pavel Stehule


> regards
> mk
>


pgsql-sql by date:

Previous
From: "Marcin Krawczyk"
Date:
Subject: Re: array variables
Next
From: "Marcin Krawczyk"
Date:
Subject: Re: array variables