Skip site navigation (1) Skip section navigation (2)

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 (view raw or flat)
Thread:
Lists: pgsql-bugspgsql-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

pgsql-bugs by date

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

pgsql-patches by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group