Re: plpgsql: returning multiple named columns from function *simply*

From: "Roger Hand" <RHand(at)kailea(dot)com>
To: "John Lawler" <postgresql(dot)org(at)tgice(dot)com>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: plpgsql: returning multiple named columns from function *simply*
Date: 2005-08-23 20:46:51
Message-ID: DB28E9B548192448A4E8C8A3C1B1E475611C8C@sj1-exch-01.us.corp.kailea.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

John Lawler wrote:
> In MSSQL, I can write a stored procedure that
> does something like this:
>
> CREATE PROCEDURE test(
> @lookup char(50))
> WITH ENCRYPTION AS BEGIN
>
> -- ... a bunch of code to do some lookup, and then ...
>
> SELECT
> @Result1 AS Result1,
> @Result2 AS Result2,
> @Result3 AS Result3,
> @Result4 AS Result4

Not sure if this a function like this does everything you may want, but it may work for you.
Disclaimer: I have not actually used the proc with the "As" for the column names,
but I'd expect it "should" work.

CREATE FUNCTION "getlogdata"("int4", "int4", "int4", "int4") RETURNS "refcursor" AS '
DECLARE curs refcursor;
BEGIN
OPEN curs FOR
SELECT logdata.datavalue As Result1,logdata.timestamp As Result2
from logdata
where logfielddatatype = $1
and graphtargetlog = $2
and (timestamp >= $3 OR $3 = 0)
and (timestamp <= $4 OR $4 = 0)
order by timestamp;
RETURN curs;
END;
' LANGUAGE 'plpgsql';

Browse pgsql-general by date

  From Date Subject
Next Message Mark Probert 2005-08-23 20:54:14 drop table before create
Previous Message Tony Caduto 2005-08-23 20:06:43 Re: plpgsql: returning multiple named columns from function