Re: return setof records

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Chris Lukenbill <chris(at)blendinteractive(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: return setof records
Date: 2006-07-28 14:13:49
Message-ID: 20060728141348.GA95234@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Thu, Jul 27, 2006 at 03:41:31PM -0500, Chris Lukenbill wrote:
> Everywhere I've looked the agreement was that making a call to the
> function had to be done as follows:
>
> SELECT * FROM sp_frontalerts_summary(1,'2006-07-27 18:08:09','2006-07-27
> 19:58:15' ) as (numitems int, region int);

That's one way. Another way would be for the function to use OUT
parameters (if you're running 8.1) or to return a custom type so
you could omit the column definition list. Then the query would be:

SELECT *
FROM sp_frontalerts_summary(1, '2006-07-27 18:08:09', '2006-07-27 19:58:15');

> So there isn't a question on that. My question is, how do I return a
> "setof record" back to the application.

The function and how you're calling it look correct except that
count() returns bigint, not int. You didn't mention what error
you're getting but I'd guess it's "wrong record type supplied in
RETURN NEXT". Try using "numitems bigint" instead of "numitems int".

--
Michael Fuhr

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Daniel Caune 2006-07-28 16:09:48 Re: [SQL] PostgreSQL server terminated by signal 11
Previous Message Tom Lane 2006-07-28 13:37:32 Re: [SQL] PostgreSQL server terminated by signal 11