Re: String Comparison and NULL

From: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
To: seijin(at)gmail(dot)com
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: String Comparison and NULL
Date: 2008-04-29 14:30:44
Message-ID: 20080429072329.A49543@megazone.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, 28 Apr 2008 seijin(at)gmail(dot)com wrote:

> I'm fairly new to PG and databases in general so this may very well be
> a problem in my thought process.
>
> If I have a simple table with an ID (integer) and Animal (text) like
> this...
>
> 1 Dog
> 2 Cat
> 3 NULL
> 4 Horse
> 5 Pig
> 6 Cat
> 7 Cat
>
> ... and I do something like "select id where animal <> 'Cat';" then
> shouldn't 1, 3, 4 and 5 be picked?

Comparisons against null with =, <> and so on return unknown not true or
false and WHERE clauses only return rows where the condition is true. You
might want to read up on the ternary (three valued) logic and nulls. I
haven't read through it but the wikipedia page on null is pretty long.

http://en.wikipedia.org/wiki/Null_%28SQL%29

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2008-04-29 14:36:53 Re: String Comparison and NULL
Previous Message Gregory Stark 2008-04-29 13:42:02 Re: Sorting nulls and empty strings together