pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Chris Lukenbill <chris@blendinteractive.com>
To: pgsql-sql@postgresql.org
Subject: return setof records
Date: Thu, 27 Jul 2006 15:41:31 -0500 (CDT)
Message-ID: <1154032891.v2.fusewebmail-168507@ffuse18> (raw)

Alright, first I'll apologize for asking this question another time.  I've
looked throught the archives and have found different ways on both the
archives and different ways in the the documentation to do this and
depending on which way I do it, I get different errors, so pick your
poison on that.

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

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

I've tried the following ways:
---------------------------------------------------------

CREATE OR REPLACE FUNCTION sp_frontalerts_summary (p_usernum int,
p_lastlogin TIMESTAMP,p_now TIMESTAMP) RETURNS SETOF RECORD AS $$

DECLARE
    returnRecord RECORD;

BEGIN

    FOR returnRecord in  select count(item) as numitems,0 as region
                    from frontalerts
                    where usernum=p_usernum and pinup=0
                LOOP
            RETURN NEXT returnRecord;
    END LOOP;


    RETURN;
END;
$$ LANGUAGE plpgsql;


---------------------------------------------------------

Also have tried it with EXECUTE after the "FOR returnRecord in" and before
the "select count(item)..."

Also have tried to do just a "select count(item) as numitems,0 as region
from frontalerts where usernum=p_usernum and pinup=0" without any type of
returning (only a "RETURNS SETOF RECORD AS $$..") (the way that the
documentation talks about doing it in one area)



Now this is a little of a simplified version, but I have the same problem
with all of the stored procs.
If you know what I'm doing wrong, please let me know.  Or if you have
anything I should possibly try, let me know that too.  I've searched high
and low and really thought I had it this time, but I guess not.

Also, sorry for such an easy question, but I'm new to PostgreSQL so this
port from MS SQL to PostgreSQL on someone else's code is kickin my butt.


Thank you in adavance for any help.

Chris




view thread (3+ messages)  latest in thread

Message-ID: <1154032891.v2.fusewebmail-168507@ffuse18>
Permalink:  ../1154032891.v2.fusewebmail-168507@ffuse18/
Also on:    postgresql.org/message-id/1154032891.v2.fusewebmail-168507@ffuse18

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: chris@blendinteractive.com
  Subject: Re: return setof records
  In-Reply-To: <1154032891.v2.fusewebmail-168507@ffuse18>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox