Referencing multiple values returned to a plpgsql function - Was: Re: Returning multiple values (but one row) in plpgsql - Mailing list pgsql-general

From Karl O. Pinc
Subject Referencing multiple values returned to a plpgsql function - Was: Re: Returning multiple values (but one row) in plpgsql
Date
Msg-id 20040914121549.C11503@mofo.meme.com
Whole thread Raw
In response to Re: Returning multiple values (but one row) in plpgsql  (Joe Conway <mail@joeconway.com>)
List pgsql-general
Once I've gotten multiple values back from a plpgsql function,
how do I actually reference those values in another plpgsql
function?  I've tried several syntaxes and keep getting errors.

Various attempts are below.

Thanks.

On 2004.09.08 15:59 Joe Conway wrote:

>
> Ah yes, that works too. For the record:
>
> CREATE TYPE returntype AS (a INT, b INT);
> CREATE OR REPLACE FUNCTION return_multiple()
>    RETURNS returntype
>    LANGUAGE plpgsql
>    AS '
>    DECLARE
>      myvar returntype%rowtype;
>    BEGIN
>      myvar.a := 1;
>      myvar.b := 2;
>      RETURN myvar;
>    END;
> ';
> SELECT * FROM return_multiple();
>  a | b
> ---+---
>  1 | 2
> (1 row)

  PostgreSQL 7.3.4 on i386-redhat-linux-gnu, compiled by GCC
i386-redhat-linux-gcc (GCC) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)


CREATE FUNCTION return_multiple2()
   RETURNS returntype
   LANGUAGE plpgsql
   AS '

   DECLARE
     myvar returntype%rowtype;
     a INT;
     b INT;

   BEGIN

--    SELECT INTO a, b FROM return_multiple();
     SELECT INTO a, b return_multiple();
     myvar.a := a;
     myvar.b := b;

--    SELECT INTO myvar return_multiple();

     RETURN  myvar;
   END;
';


Karl <kop@meme.com>
Free Software:  "You don't pay back, you pay forward."
                  -- Robert A. Heinlein

pgsql-general by date:

Previous
From: "Nick Hajek"
Date:
Subject: 8.0.0 beta 2, void type
Next
From: Vivek Khera
Date:
Subject: Re: disk performance benchmarks