Search Postgresql Archives

Re: Record with a field consisting of table rows

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

 



Hi,

> Nope, see my reply from yesterday around 20:23
> You can return a table instead, with the count added as an
> extra column.

I did see your solution, but note that it does not return a tuple
consisting of an integer and a setof (as I wanted), but instead
returns a setof of a tuple.

I still haven't found a solution to the original problem.  The
best I can do so far is to create a function that returns a tuple
consisting of an int and the first row of table results (see below).
Any more thoughts?

Best regards,
Jon

create table users
        (
        uid     int4 not null,
        name    text not null,
        age     int4 not null,
        primary key (uid)
        );

create type page_t AS
        (
        total   int4,
        users   users
        );


create function get_page ()
returns page_t
language plpgsql as
$$
declare
        _total  int4;
        _users  users;
        _page   page_t;
begin
        select count (*) from users into _total;
        select * from users limit 10 into _users;
        _page := row (_total, _users);
        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


[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