Monday, February 2, 2009

Checking Null Values

I tried to check null values with
expression = NULL

but i did not get any results. Obviously the results are available for my query and i was wondering why always result set was zero. Here is the solution

--------------------------------------

To check whether a value is or is not null, use the constructs
expression IS NULL
expression IS NOT NULL

or the equivalent, but nonstandard, constructs

expression ISNULL
expression NOTNULL

Do not write expression = NULL because NULL is not "equal to" NULL. (The null value represents an unknown value, and it is not known whether two unknown values are equal.) This behavior conforms to the SQL standard.

Tip: Some applications may expect that expression = NULL returns true if expression evaluates to the null value. It is highly recommended that these applications be modified to comply with the SQL standard. However, if that cannot be done the transform_null_equals configuration variable is available. If it is enabled, PostgreSQL will convert x = NULL clauses to x IS NULL. This was the default behavior in PostgreSQL releases 6.5 through 7.1.

---------------------------------------------------------------------

 So always remember to use IS NULL to check the null values 



No comments: