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 D3D51D1B51A for ; Mon, 8 Sep 2003 07:33:02 +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 76894-04 for ; Mon, 8 Sep 2003 04:32:32 -0300 (ADT) Received: from smtp.lewczuk.com (unknown [195.150.168.118]) by svr1.postgresql.org (Postfix) with SMTP id 7A7A9D1B53B for ; Mon, 8 Sep 2003 04:32:29 -0300 (ADT) Received: (qmail 7243 invoked by uid 700); 8 Sep 2003 07:32:24 -0000 Received: from unknown (HELO marek) (62.233.139.198) by 195.150.168.118 with SMTP; 8 Sep 2003 07:32:23 -0000 Reply-To: From: "Marek Lewczuk" To: "Lista dyskusyjna pgsql-general" , "Lista dyskusyjna pgsql-sql" , "Lista dyskusyjna pgsql-bugs" Subject: plPGSQL bug in function creation Date: Mon, 8 Sep 2003 09:32:28 +0100 Organization: LEWCZUK.COM Message-ID: <004901c375e3$bd31f660$4701a8c0@marek> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.2627 X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Importance: Normal X-Virus-Scanned: by amavisd-new at postgresql.org X-Spam-Status: No, hits=1.0 tagged_above=0.0 required=5.0 tests=UPPERCASE_25_50 X-Spam-Level: * X-Archive-Number: 200309/75 X-Sequence-Number: 6706 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