From: | Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> |
---|---|
To: | Michael Sacket <msacket(at)gammastream(dot)com> |
Cc: | PG-General Mailing List <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: NULL value comparison |
Date: | 2012-08-22 13:28:39 |
Message-ID: | CAFj8pRA_DiwRJukZfsQu0St6pZcRdfO+hwHS=erRvTzjgO+fVw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
2012/8/22 Michael Sacket <msacket(at)gammastream(dot)com>:
> 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.
no - NULL is not comparable with any value
your query should be
WHERE is_enabled <> 'Y' or is_enabled IS NULL
or
WHERE is_enabled IS DISTINCT FROM 'Y'
Regards
Pavel Stehule
>
> 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
From | Date | Subject | |
---|---|---|---|
Next Message | Adrian Klaver | 2012-08-22 13:30:46 | Re: NULL value comparison |
Previous Message | Michael Sacket | 2012-08-22 13:23:29 | NULL value comparison |