Re: BUG #2108: Function with OUT parameters not recognized, using plpgsql

From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: Tony <tony(at)vectorsalad(dot)com>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #2108: Function with OUT parameters not recognized, using plpgsql
Date: 2005-12-12 14:08:36
Message-ID: 20051212140835.GH19555@surnet.cl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-patches

Tony wrote:

> CREATE OR REPLACE FUNCTION f_multiparam (
> i1 integer,
> i2 varchar,
> OUT o1 varchar
> ) AS
> $$
> BEGIN
> o1 := 'i2 was ' || i2;
> END;
> $$
> LANGUAGE plpgsql;
>
> CREATE OR REPLACE FUNCTION f_showperformstatus () RETURNS varchar AS
> $$
> DECLARE
> outparameter varchar;
> BEGIN
> PERFORM f_multiparam(1, 'hello', outparameter);
> RETURN 'successfully run';
> END;
> $$
> LANGUAGE plpgsql;

You are misunderstanding how are functions with OUT params supposed to
be called, I think. Try this:

CREATE OR REPLACE FUNCTION f_multiparam (
i1 integer,
i2 varchar,
OUT o1 varchar
) AS
$$
BEGIN
o1 := 'i2 was ' || i2;
END;
$$
LANGUAGE plpgsql;

CREATE OR REPLACE FUNCTION f_showperformstatus () RETURNS varchar AS
$$
DECLARE
outparameter varchar;
BEGIN
SELECT INTO outparameter f_multiparam(1, 'hello');
RAISE NOTICE 'the out param is %', outparameter;
RETURN 'successfully run';
END;
$$
LANGUAGE plpgsql;

The output I get is what I'd expect:

alvherre=# select f_showperformstatus();
NOTICE: the out param is i2 was hello
f_showperformstatus
---------------------
successfully run
(1 fila)

I think this also applies to your INOUT report, but I haven't checked.

--
Alvaro Herrera http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Alvaro Herrera 2005-12-12 15:31:07 Re: [BUGS] BUG #2108: Function with OUT parameters not recognized, using plpgsql
Previous Message Micha Szelg 2005-12-12 13:38:37 BUG #2109: NULL=NULL is false

Browse pgsql-patches by date

  From Date Subject
Next Message Bruce Momjian 2005-12-12 14:16:23 Re: farsi translation of postgresql FAQ updated
Previous Message Bruce Momjian 2005-12-12 13:36:19 Re: TODO item: list prepared queries