Re: NULL value comparison

From: Thalis Kalfigkopoulos <tkalfigo(at)gmail(dot)com>
To: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: NULL value comparison
Date: 2012-08-22 13:43:13
Message-ID: CAEkCx9GSDUiN5ma6afJi2ieMygXqHS1c7Ww+1yZKoDNd6_Mf3g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi Michael.

NULL is not any specific value. Thus Pg correctly doesnot tell you that it
is <>'Y'. It is NULL means that we dont know the value. Thus it may be 'Y'
as much as it may not be 'Y'. The comparison is not applicable in the case
of NULL and that's why there are the IS NULL and IS NOT NULL operators.

Regards,
Thalis

On Aug 22, 2012 10:24 AM, "Michael Sacket" <msacket(at)gammastream(dot)com> wrote:
>
> Good Day,
>
> I'm trying to figure out why a postgresql query doesn't return what I'd
expect with a query like this where there are NULL values:
>
> select * from users where is_enabled<>'Y';
>
> I'm expecting it to return all records where is_enabled is 'N' or NULL.
Perhaps my expectations are misguided. Any thoughts would be appreciated.
>
> Thanks!
> Michael
>
>
> Example:
>
> CREATE TABLE users (
> "name" char(50) NOT NULL,
> "is_enabled" char
> )
>
> insert into users (name, is_enabled) values ('Michael', 'Y');
> insert into users (name, is_enabled) values ('Jeremy', 'N');
> insert into users (name, is_enabled) values ('Sherry', NULL);
>
>
> select * from users where is_enabled<>'Y';
> +----------------------------------------------------+------------+
> | name | is_enabled |
> +----------------------------------------------------+------------+
> | Jeremy | N |
> +----------------------------------------------------+------------+
> 1 rows in set (0.03 sec)
>
>
>
>
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Michael Sacket 2012-08-22 14:58:28 Re: NULL value comparison
Previous Message David Johnston 2012-08-22 13:37:08 Re: NULL value comparison