NOTNULL accepting nulls?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

NOTNULL accepting nulls?

Post by GeXus »

I set a column to not null, yet it is still accepting null values... is white space a value?
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

white space, "", " ", '', ' ' are not equal to NULL.



ps: Even NULL isn't equal to NULL ;)
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Post by GeXus »

Ah I see.... is there a way to go about this?

Basically i'm using one page to add and update, so i have a select clause, and if column B doesnt exist, it will add.. or else it will update if it does exist.. the problem is that it is always seeing it as existing because it is creating empty space...
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Handle it at the php side..

If strlen($input) == 0 -> generate query with NULL value , otherwise generate query with $input
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

timvw wrote:Handle it at the php side..

If strlen($input) == 0 -> generate query with NULL value , otherwise generate query with $input

try a trigger before update on the column in the table and make empty values to NULL. It will be cool.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Untill the day i really want to add just '' ;)

I appreciate that a dbms validates my data, but usually i do not appreciate when it decided to modify it..
Post Reply