From: | "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com> |
---|---|
To: | "Marcin Krawczyk" <jankes(dot)mk(at)gmail(dot)com> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: array variables |
Date: | 2008-11-13 09:30:43 |
Message-ID: | 162867790811130130l3ff2bfdcl33748352858f40e1@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Hello
2008/11/13 Marcin Krawczyk <jankes(dot)mk(at)gmail(dot)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 | 10
20 | 20
(2 rows)
regards
Pavel Stehule
> regards
> mk
>
From | Date | Subject | |
---|---|---|---|
Next Message | Achilleas Mantzios | 2008-11-13 09:39:03 | Re: array variables |
Previous Message | Marcin Krawczyk | 2008-11-13 09:13:30 | Re: array variables |