Re: postgresql function not accepting null values in select statement

From: Richard Huxton <dev(at)archonet(dot)com>
To: Jyoti Seth <jyotiseth2001(at)gmail(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: postgresql function not accepting null values in select statement
Date: 2008-02-22 09:33:59
Message-ID: 47BE9707.3060109@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Robins Tharakan 2008-02-22 09:34:06 Re: postgresql function not accepting null values in select statement
Previous Message Jyoti Seth 2008-02-22 09:22:55 Re: postgresql function not accepting null values in select statement