From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Jon Smark <jon(dot)smark(at)yahoo(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Record with a field consisting of table rows |
Date: | 2011-01-13 17:20:20 |
Message-ID: | 19386.1294939220@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Jon Smark <jon(dot)smark(at)yahoo(dot)com> writes:
> create type page_t AS
> (
> total int4,
> users user_t[]
> );
> create function get_page ()
> returns page_t
> language plpgsql as
> $$
> declare
> _page page_t;
> begin
> _page.total := select count (*) from users;
> select * into _page.users from users limit 10;
> return _page;
> end
> $$;
That is certainly not going to work: that select does not produce an
array, it produces a column of user_t (of which SELECT INTO is only
gonna take the first, anyway).
Untested, but I think you'd have better results with
_page.users := array(select users from users limit 10);
It'd also be smart to get rid of user_t and rely directly on the "users"
rowtype associated with the users table.
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Bruce Momjian | 2011-01-13 17:32:47 | Re: C++ keywords in headers (was Re: [GENERAL] #include <funcapi.h>) |
Previous Message | Håvard Wahl Kongsgård | 2011-01-13 16:47:39 | Performance on multiple OR conditions inside () |