X-Original-To: pgsql-interfaces-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id EA9B23A5F7D for ; Thu, 13 Jan 2005 19:50:46 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 95991-04 for ; Thu, 13 Jan 2005 19:50:37 +0000 (GMT) Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by svr1.postgresql.org (Postfix) with ESMTP id 8DAF33A5DB3 for ; Thu, 13 Jan 2005 19:50:37 +0000 (GMT) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.1/8.13.1) with ESMTP id j0DJoW61053276 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 13 Jan 2005 12:50:34 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.1/8.13.1) with ESMTP id j0DJoWnE040980; Thu, 13 Jan 2005 12:50:32 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.1/8.13.1/Submit) id j0DJoVtP040979; Thu, 13 Jan 2005 12:50:31 -0700 (MST) (envelope-from mfuhr) Date: Thu, 13 Jan 2005 12:50:31 -0700 From: Michael Fuhr To: Benno =?iso-8859-1?Q?P=FCtz?= Cc: pgsql-interfaces@postgresql.org Subject: Re: How to detect NULL in VarChar (C function) Message-ID: <20050113195031.GA40861@winnie.fuhr.org> References: <41E6A794.6020701@mpipsykl.mpg.de> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <41E6A794.6020701@mpipsykl.mpg.de> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.003 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200501/4 X-Sequence-Number: 5230 On Thu, Jan 13, 2005 at 05:53:40PM +0100, Benno Pütz wrote: > I try to write a function that combines two varchar columns. > > Now the problem arose that (either) one of te columns may contain a NULL > value, in which case the return value seems to become NULL. What do you mean "seems" to become NULL? Is it NULL or not? You can check with IS NULL: SELECT foo(value1, value2) IS NULL; > I have not been able to find a description of how to detect NULL values > in VarChar variables passed to C-functions to catch those cases. If you're using the version-1 calling conventions then you can use PG_ARGISNULL(); this macro is mentioned in the "C-Language Functions" section of the "Extending SQL" chapter in the documentation. If you created the function as STRICT (aka RETURNS NULL ON NULL INPUT) and any of the arguments are NULL, then the function won't be called at all and the return value will be NULL. If you want to handle NULL values within the function then don't declare it STRICT. -- Michael Fuhr http://www.fuhr.org/~mfuhr/