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

From: "Karl O(dot) Pinc" <kop(at)meme(dot)com>
To: Joe Conway <mail(at)joeconway(dot)com>
Cc: "Karl O(dot) Pinc" <kop(at)meme(dot)com>, Ron St-Pierre <rstpierre(at)syscor(dot)com>, pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Referencing multiple values returned to a plpgsql function - Was: Re: Returning multiple values (but one row) in plpgsql
Date: 2004-09-14 17:15:49
Message-ID: 20040914121549.C11503@mofo.meme.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)meme(dot)com>
Free Software: "You don't pay back, you pay forward."
-- Robert A. Heinlein

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Vivek Khera 2004-09-14 17:28:59 Re: disk performance benchmarks
Previous Message Bruno Wolff III 2004-09-14 16:42:21 Re: Firewall Security Requirements for Postgresql Access