plPGSQL bug in function creation - Mailing list pgsql-bugs

From Marek Lewczuk
Subject plPGSQL bug in function creation
Date
Msg-id 004901c375e3$bd31f660$4701a8c0@marek
Whole thread Raw
Responses Re: [SQL] plPGSQL bug in function creation  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: [GENERAL] plPGSQL bug in function creation  (Richard Huxton <dev@archonet.com>)
Re: [GENERAL] plPGSQL bug in function creation  (Dennis Gearon <gearond@fireserve.net>)
List pgsql-bugs
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




pgsql-bugs by date:

Previous
From: Tom Lane
Date:
Subject: Re: help with mac osx 10.2.6
Next
From: pgsql-bugs@postgresql.org
Date:
Subject: VIRUS INFECTED MESSAGE NOT DELIVERED