X-Original-To: pgsql-bugs-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 72356D1B4E4; Mon, 8 Sep 2003 14:16:33 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 47885-07; Mon, 8 Sep 2003 11:16:06 -0300 (ADT) Received: from phaze.fireserve.net (phaze.fireserve.net [207.109.249.2]) by svr1.postgresql.org (Postfix) with ESMTP id F1C7ED1B519; Mon, 8 Sep 2003 11:16:00 -0300 (ADT) Received: from fireserve.net (dh0105.moore-s.fireserve.net [207.109.249.198]) by phaze.fireserve.net (8.11.6p2/linuxconf) with ESMTP id h88EHBt03144; Mon, 8 Sep 2003 07:17:11 -0700 Message-ID: <3F5C8EFB.7090101@fireserve.net> Date: Mon, 08 Sep 2003 07:15:23 -0700 From: Dennis Gearon User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4) Gecko/20030624 X-Accept-Language: en-us, en, ru MIME-Version: 1.0 To: newsy@lewczuk.com Cc: Lista dyskusyjna pgsql-general , Lista dyskusyjna pgsql-sql , Lista dyskusyjna pgsql-bugs Subject: Re: [GENERAL] plPGSQL bug in function creation References: <004901c375e3$bd31f660$4701a8c0@marek> In-Reply-To: <004901c375e3$bd31f660$4701a8c0@marek> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-MailScanner: Found to be clean X-MailScanner-SpamCheck: not spam, SpamAssassin (score=-4.29, required 6, AWL, BAYES_00, UPPERCASE_25_50) X-Virus-Scanned: by amavisd-new at postgresql.org X-Spam-Status: No, hits=0.1 tagged_above=0.0 required=5.0 tests=EMAIL_ATTRIBUTION, IN_REP_TO, REFERENCES, REPLY_WITH_QUOTES, UPPERCASE_25_50, USER_AGENT_MOZILLA_UA X-Spam-Level: X-Archive-Number: 200309/90 X-Sequence-Number: 6721 Marek Lewczuk wrote: >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 > > > > >---------------------------(end of broadcast)--------------------------- >TIP 8: explain analyze is your friend > > > You can only test for NULL with 'IS NULL'. NULL is NOT: FALSE, 0, or F