Re: plpgsql: returning multiple named columns from function *simply* - Mailing list pgsql-general

From Roger Hand
Subject Re: plpgsql: returning multiple named columns from function *simply*
Date
Msg-id DB28E9B548192448A4E8C8A3C1B1E475611C8C@sj1-exch-01.us.corp.kailea.com
Whole thread Raw
In response to plpgsql: returning multiple named columns from function *simply*  (John Lawler <postgresql.org@tgice.com>)
List 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';

pgsql-general by date:

Previous
From: Tony Caduto
Date:
Subject: Re: plpgsql: returning multiple named columns from function
Next
From: Mark Probert
Date:
Subject: drop table before create