From: | "scott(dot)marlowe" <scott(dot)marlowe(at)ihs(dot)com> |
---|---|
To: | John Harrold <jmh17(at)pitt(dot)edu> |
Cc: | posgresql hotline <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: what is null |
Date: | 2003-08-04 20:54:29 |
Message-ID: | Pine.LNX.4.33.0308041451480.10925-100000@css120.ihs.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Mon, 4 Aug 2003, John Harrold wrote:
> i'm trying to alter a table call it 'my_table' and i'm trying to set the
> field 'my_id' to prevent null values from being inserted. when i run the
> following:
>
> ALTER TABLE my_table ALTER my_id SET NOT NULL;
>
> i get:
>
> ERROR: ALTER TABLE: Attribute "my_id" contains NULL values
>
> so i want to find out which rows have null values so i run:
>
> my=# select my_id from my_table where my_id=NULL;
> my_id
> ---------
> (0 rows)
>
>
> so this would indicate to me that there are no rows in which my_id is NULL.
> so what is preventing me from altering the table? or am i just doing
> something wrong?
Yep, you are. But it's a common mistake for folks just learning about
NULL.
Nothing can be equal to NULL, since NULL by it's definition isn't even
equal to itself:
What you need is "is null"
select * from table where field IS NULL;
From | Date | Subject | |
---|---|---|---|
Next Message | John Harrold | 2003-08-04 20:54:59 | what is null |
Previous Message | Tom Lane | 2003-08-04 20:48:58 | Re: plPHP -- sort of an announcement.. but not commercial |