Re: NULL != text ? - Mailing list pgsql-general

From Michael Fuhr
Subject Re: NULL != text ?
Date
Msg-id 20051020064406.GA73462@winnie.fuhr.org
Whole thread Raw
In response to NULL != text ?  (CSN <cool_screen_name90001@yahoo.com>)
Responses Re: NULL != text ?  (Michael Glaesemann <grzm@myrealbox.com>)
Re: NULL != text ?  (CSN <cool_screen_name90001@yahoo.com>)
List pgsql-general
On Wed, Oct 19, 2005 at 11:04:36PM -0700, CSN wrote:
> So, does NULL != 'abc' always evaluate to false?

It never evaluates to false -- it evaluates to NULL.

http://www.postgresql.org/docs/8.0/interactive/functions-comparison.html

  The ordinary comparison operators yield null (signifying "unknown")
  when either input is null.  Another way to do comparisons is with the
  IS DISTINCT FROM construct:

  expression IS DISTINCT FROM expression

  For non-null inputs this is the same as the <> operator.  However,
  when both inputs are null it will return false, and when just one
  input is null it will return true.  Thus it effectively acts as
  though null were a normal data value, rather than "unknown".

Examples:

test=> SELECT NULL = 'abc';
 ?column?
----------

(1 row)

test=> SELECT NULL <> 'abc';
 ?column?
----------

(1 row)

test=> SELECT NULL IS DISTINCT FROM 'abc';
 ?column?
----------
 t
(1 row)

test=> SELECT NULL IS DISTINCT FROM NULL;
 ?column?
----------
 f
(1 row)

--
Michael Fuhr

pgsql-general by date:

Previous
From: Michael Glaesemann
Date:
Subject: Re: NULL != text ?
Next
From: "Roger Hand"
Date:
Subject: Re: PSQL suggested enhancement