Search Postgresql Archives

Re: Record with a field consisting of table rows

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello

try to SELECT INTO ARRAY(SELECT user_t FROM users LIMIT 10) _page.users;

Regards

Pavel Stehule


2011/1/13 Jon Smark <jon.smark@xxxxxxxxx>:
> Hi,
>
> I am trying to create a PL/pgSQL function whose return type is a tuple
> consisting of an integer and a list of table rows. ÂI emulate the tuple
> by defining a record 'page_t' with the two fields; however, the naÃve
> approach of doing a SELECT INTO one the record's fields does not work
> (see function 'get_page') below. ÂAm I missing something obvious here?
>
> Thanks in advance!
> Jon
>
>
> create table users
> Â Â Â Â(
>    Âuid   int4 not null,
>    Âname  Âtext not null,
>    Âage   int4 not null,
> Â Â Â Âprimary key (uid)
> Â Â Â Â);
>
> create type user_t AS
> Â Â Â Â(
>    Âuid   int4,
>    Âname  Âtext,
>    Âage   int4
> Â Â Â Â);
>
> 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
> $$;
>
>
>
>
>
> --
> Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux