Re: IS NULL seems to return false, even when parameter is NULL

From: Richard Huxton <dev(at)archonet(dot)com>
To: Andrus <kobruleht2(at)hot(dot)ee>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: IS NULL seems to return false, even when parameter is NULL
Date: 2008-10-20 11:34:41
Message-ID: 48FC6CD1.4080106@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Andrus wrote:
>> I have a strange problem with the following condition in a SELECT:
>> AND (("TableData" = "inDate") OR ("inDate" IS NULL))
>>
>> it works perfectly when the input date in the function (inDate) matchs
>> a date in the table, but it does not work when the parameter inDate is
>> NULL.
>> I recall the function with pgadmin writing NULL as paramater.
>> It seems that ("inDate" IS NULL) never returns true, even when the
>> parameter is null...
>> What's wrong?
>
> Order is wrong, change it to
>> AND (("inDate" IS NULL) OR ("TableData" = "inDate") )
>
> PostgreSQL OR is not commutative if left operand evaluates to NULL.

Seems to work here:

select (true or null) as a, (null or true) as b, (null or false) as c,
(false or null) as d;
a | b | c | d
---+---+---+---
t | t | |
(1 row)

--
Richard Huxton
Archonet Ltd

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Sam Mason 2008-10-20 11:40:12 Re: removing a portion of text
Previous Message Csaba Nagy 2008-10-20 11:32:59 Re: Fwd: Copying Blobs between two tables using Insert stmt