Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 397FA2E00C5 for ; Fri, 22 Feb 2008 05:34:06 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 84810-04 for ; Fri, 22 Feb 2008 05:34:03 -0400 (AST) Received: from ptb-relay03.plus.net (ptb-relay03.plus.net [212.159.14.214]) by postgresql.org (Postfix) with ESMTP id AB00F2E00D5 for ; Fri, 22 Feb 2008 05:34:03 -0400 (AST) Received: from [84.51.143.99] (helo=server3.office.archonet.com) by ptb-relay03.plus.net with esmtp (Exim) id 1JSUI6-00049f-EE; Fri, 22 Feb 2008 09:34:02 +0000 Received: from [192.168.1.36] (dell36.office.archonet.com [192.168.1.36]) by server3.office.archonet.com (Postfix) with ESMTP id 1A8D0274053; Fri, 22 Feb 2008 09:33:59 +0000 (GMT) Message-ID: <47BE9707.3060109@archonet.com> Date: Fri, 22 Feb 2008 09:33:59 +0000 From: Richard Huxton User-Agent: Thunderbird 2.0.0.9 (X11/20071031) MIME-Version: 1.0 To: Jyoti Seth CC: pgsql-sql@postgresql.org Subject: Re: postgresql function not accepting null values in select statement References: <001501c8752d$391c8e50$ab55aaf0$@com> <47BE9058.9030909@archonet.com> <001a01c87534$84eea280$8ecbe780$@com> In-Reply-To: <001a01c87534$84eea280$8ecbe780$@com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Plusnet-Relay: 9c640484384e9d4c308d79b2ac7cfd5e X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200802/161 X-Sequence-Number: 30252 Jyoti Seth wrote: > Hi, > > I have a the following procedure > > CREATE OR REPLACE FUNCTION getfunctionaries(p_statecd integer) > SELECT f.functionaryid, f.category,f.description > FROM functionaries f > where f.statecd=p_statecd > In the functionaries table statecd is a null field. When I pass some integer > value to the above procedure it works correctly but if I pass null value in > p_statecd it doesn't show anything whereas it has values and if I write the > select statement separately it gives values You can't be getting results from a query WHERE statecd = NULL, because NULL = NULL returns NULL, which is equivalent to false in a WHERE clause. If you want to check for NULL you need to use statecd IS NULL, but if you are treating it like a value then you're using it incorrectly. -- Richard Huxton Archonet Ltd