Re: Record with a field consisting of table rows

From: Jon Smark <jon(dot)smark(at)yahoo(dot)com>
To: Alban Hertroys <dalroi(at)solfertje(dot)student(dot)utwente(dot)nl>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Record with a field consisting of table rows
Date: 2011-01-15 16:01:06
Message-ID: 683638.47205.qm@web112803.mail.gq1.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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
$$;

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alban Hertroys 2011-01-15 17:32:40 Re: Record with a field consisting of table rows
Previous Message Craig Ringer 2011-01-15 13:27:10 Re: Install PostgreSQL as part of a desktop application, but how to coop with existing installations?