plPGSQL bug in function creation

From: "Marek Lewczuk" <newsy(at)lewczuk(dot)com>
To: "Lista dyskusyjna pgsql-general" <pgsql-general(at)postgresql(dot)org>, "Lista dyskusyjna pgsql-sql" <pgsql-sql(at)postgresql(dot)org>, "Lista dyskusyjna pgsql-bugs" <pgsql-bugs(at)postgresql(dot)org>
Subject: plPGSQL bug in function creation
Date: 2003-09-08 08:32:28
Message-ID: 004901c375e3$bd31f660$4701a8c0@marek
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-general pgsql-sql

Hello,
I think that there is a bug in plPGSQL - or maybe I don't know something
about this language. Try to create this function

Ok., this is the function created in plPGSQL:

CREATE FUNCTION "public"."test" (text, text) RETURNS text AS'
BEGIN
IF $1 THEN
RETURN $1;
ELSE
RETURN $2;
END IF;
END;
'LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER;

If you will execute SELECT test('tess', 'erer') -> then "tess" will be
returned. If you will execute: SELECT test(NULL, 'buuu'); -> then it
will return NULL, but it should return "buuu". I tried to figure out why
it is happening so i modifye this function to this:

CREATE FUNCTION "public"."test" (text, text) RETURNS text AS'
BEGIN
RETURN 'test';
END;
'LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER;

And when i execute: SELECT test(NULL, 'buuu'); -> it returns me NULL
value, when it should return "buuu". Well I think that something is
wrong here.

If I will modify this function again to this:

CREATE FUNCTION "public"."test" (varchar, varchar) RETURNS text AS'
BEGIN
IF $1 THEN
RETURN $1;
ELSE
RETURN $2;
END IF;
END;
'LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER;

Everything is working OK.. So the problem is in TEXT type definition.

I'm using PG 7.3.1 on Win/Cyg

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message A.Bhuvaneswaran 2003-09-08 11:37:20 heap_mark4update: (am)invalid tid
Previous Message pgsql-bugs 2003-09-08 07:55:56 VIRUS INFECTED MESSAGE NOT DELIVERED

Browse pgsql-general by date

  From Date Subject
Next Message Paul Thomas 2003-09-08 10:00:13 Re: Cannot createdb
Previous Message Kris Jurka 2003-09-08 08:18:31 Re: Unix domain instead of TCP socket connections with

Browse pgsql-sql by date

  From Date Subject
Next Message Richard Huxton 2003-09-08 12:09:16 Re: [GENERAL] plPGSQL bug in function creation
Previous Message Kris Jurka 2003-09-08 08:21:44 Re: MINUS & ROWNUM in PostGres