X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 7C1809FB263 for ; Fri, 28 Jul 2006 15:01:55 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 69675-10 for ; Fri, 28 Jul 2006 15:01:37 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from nf-out-0910.google.com (nf-out-0910.google.com [64.233.182.188]) by postgresql.org (Postfix) with ESMTP id 777E79FA4E3 for ; Fri, 28 Jul 2006 15:01:33 -0300 (ADT) Received: by nf-out-0910.google.com with SMTP id p77so261081nfc for ; Fri, 28 Jul 2006 11:01:30 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:references:x-google-sender-auth; b=sZsHdzH522EwejA1XWQJW1jUq5hdzsT+MMWA4NkZZleFvKinPLv7zR+SRvU2GKulOhQz5jH0jXQjB77PpptfF+L4vufCmX20UQuYMUnmx1m40Kim/k2ah+33mQPFEOcVYqjVFldMTrWZtXAenHBqzbO4gt834Cz/TBB06Pr3644= Received: by 10.48.1.4 with SMTP id 4mr1049384nfa; Fri, 28 Jul 2006 11:01:30 -0700 (PDT) Received: by 10.48.243.8 with HTTP; Fri, 28 Jul 2006 11:01:30 -0700 (PDT) Message-ID: Date: Fri, 28 Jul 2006 13:01:30 -0500 From: "Chris Lukenbill" To: "Michael Fuhr" Subject: Re: return setof records Cc: pgsql-sql@postgresql.org In-Reply-To: <20060728141348.GA95234@winnie.fuhr.org> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_254242_31586476.1154109690712" References: <1154032891.v2.fusewebmail-168507@ffuse18> <20060728141348.GA95234@winnie.fuhr.org> X-Google-Sender-Auth: 4114e341ec150bd4 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=HTML_MESSAGE, SPF_PASS X-Spam-Level: X-Archive-Number: 200607/359 X-Sequence-Number: 25933 ------=_Part_254242_31586476.1154109690712 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline I think that actually solved the problem. The fact that I was sending back a bigint. One of those things that's hard to spot when I don't know if I was on the right track to begin with. Thank you everyone for your help. Chris On 7/28/06, Michael Fuhr wrote: > > 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 > > ------=_Part_254242_31586476.1154109690712 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline I think that actually solved the problem. The fact that I was sending back a bigint.  One of those things that's hard to spot when I don't know if I was on the right track to begin with.  Thank you everyone for your help.

Chris

On 7/28/06, Michael Fuhr <mike@fuhr.org> wrote:
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


------=_Part_254242_31586476.1154109690712--