Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-11-2012, 03:02 PM   PM User | #1
Trki
Regular Coder

 
Join Date: Jan 2012
Location: Slovakia
Posts: 106
Thanks: 9
Thanked 0 Times in 0 Posts
Trki is an unknown quantity at this point
collum = " "

Hi guys ... i need help ... i want do update to a empty collum. Do you know how? its posible? i tried cookies='null' or cookies=null or NULL,NULL but ... nothing :P

the cookies collum is a varchar btw.

UPDATE pocitadlo_online SET timestamp='6' WHERE ip='44.444.44.444' AND cookies=' '
Trki is offline   Reply With Quote
Old 01-11-2012, 03:21 PM   PM User | #2
_Aerospace_Eng_
Supreme Master coder!


 
_Aerospace_Eng_'s Avatar
 
Join Date: Dec 2004
Location: In a place far, far away...
Posts: 19,293
Thanks: 2
Thanked 1,044 Times in 1,020 Posts
_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light
What field type is cookies?
__________________
||||If you are getting paid to do a job, don't ask for help on it!||||
_Aerospace_Eng_ is offline   Reply With Quote
Old 01-11-2012, 03:55 PM   PM User | #3
guelphdad
Super Moderator


 
guelphdad's Avatar
 
Join Date: Mar 2006
Location: St. Catharines, Ontario Canada
Posts: 2,629
Thanks: 4
Thanked 147 Times in 138 Posts
guelphdad will become famous soon enoughguelphdad will become famous soon enough
= NULL would be incorrect. you need to test for cookies IS NULL if it is actually a null value in the column. (I.e. not spaces which you are testing for currently with cookies = ' ')
guelphdad is offline   Reply With Quote
Old 01-11-2012, 04:05 PM   PM User | #4
Trki
Regular Coder

 
Join Date: Jan 2012
Location: Slovakia
Posts: 106
Thanks: 9
Thanked 0 Times in 0 Posts
Trki is an unknown quantity at this point
Quote:
Originally Posted by _Aerospace_Eng_ View Post
What field type is cookies?
i said varchar
Trki is offline   Reply With Quote
Old 01-11-2012, 04:06 PM   PM User | #5
Trki
Regular Coder

 
Join Date: Jan 2012
Location: Slovakia
Posts: 106
Thanks: 9
Thanked 0 Times in 0 Posts
Trki is an unknown quantity at this point
Quote:
Originally Posted by guelphdad View Post
= NULL would be incorrect. you need to test for cookies IS NULL if it is actually a null value in the column. (I.e. not spaces which you are testing for currently with cookies = ' ')
hm... ah sorry i have no idea what did you say :P could you please say it more straightly ? :P or edit my code
Trki is offline   Reply With Quote
Old 01-11-2012, 08:00 PM   PM User | #6
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,232
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Here's what I would do:
Code:
UPDATE pocitadlo_online 
SET timestamp='6' 
WHERE ip='44.444.44.444' AND TRIM(IFNULL(cookies,'')) = ''
That should cover all possibilities:
Code:
-- NULL
-- ''   
-- '          '
That is, blank strings *AND* strings containing nothing but space characters *AND* NULL values will all be treated the same.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is online now   Reply With Quote
Users who have thanked Old Pedant for this post:
Trki (01-11-2012)
Old 01-11-2012, 09:36 PM   PM User | #7
Trki
Regular Coder

 
Join Date: Jan 2012
Location: Slovakia
Posts: 106
Thanks: 9
Thanked 0 Times in 0 Posts
Trki is an unknown quantity at this point
''

Quote:
Originally Posted by Old Pedant View Post
Here's what I would do:
Code:
UPDATE pocitadlo_online 
SET timestamp='6' 
WHERE ip='44.444.44.444' AND TRIM(IFNULL(cookies,'')) = ''
That should cover all possibilities:
Code:
-- NULL
-- ''   
-- '          '
That is, blank strings *AND* strings containing nothing but space characters *AND* NULL values will all be treated the same.
thx that was brilliant. I again learned something. But i little be dont understand the full code i understand AND TRIM(without spaces) but... could you explain the next code ... how it means IFNULL(cookies,'')) = ''

and why it didnt works on cookies=''

it... is meaning like " if is the value of cookies -> '' equal to '' ?

*sorry for english
Trki is offline   Reply With Quote
Old 01-11-2012, 10:31 PM   PM User | #8
guelphdad
Super Moderator


 
guelphdad's Avatar
 
Join Date: Mar 2006
Location: St. Catharines, Ontario Canada
Posts: 2,629
Thanks: 4
Thanked 147 Times in 138 Posts
guelphdad will become famous soon enoughguelphdad will become famous soon enough
when you test for a value of NULL you can't use an equals sign.

SELECT * FROM yourtable WHERE yourcolumn = NULL

is incorrect

SELECT * FROM yourtable WHERE yourcolumn IS NULL

is correct. NULL does not match anything, even another NULL so you can't test with =

more likely though you were using an empty string with perhaps one or more spaces.

the TRIM takes care of spaces and the IFNULL also checks for NULL condition so both were done in that example posted by Old Pedant.
guelphdad is offline   Reply With Quote
Users who have thanked guelphdad for this post:
Trki (01-11-2012)
Old 01-11-2012, 10:44 PM   PM User | #9
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,232
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Also, in the query you showed, you were *NOT* testing for a blank string.

You were testing for a string with ONE SPACE in it.

And that is a very very different thing.


... AND cookies=' '

See the space in there? That would *ONLY* match a field that indeed had a single space stored in it.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is online now   Reply With Quote
Users who have thanked Old Pedant for this post:
Trki (01-11-2012)
Old 01-11-2012, 11:14 PM   PM User | #10
Trki
Regular Coder

 
Join Date: Jan 2012
Location: Slovakia
Posts: 106
Thanks: 9
Thanked 0 Times in 0 Posts
Trki is an unknown quantity at this point
Quote:
Originally Posted by guelphdad View Post
when you test for a value of NULL you can't use an equals sign.

SELECT * FROM yourtable WHERE yourcolumn = NULL

is incorrect

SELECT * FROM yourtable WHERE yourcolumn IS NULL

is correct. NULL does not match anything, even another NULL so you can't test with =

more likely though you were using an empty string with perhaps one or more spaces.

the TRIM takes care of spaces and the IFNULL also checks for NULL condition so both were done in that example posted by Old Pedant.
Quote:
Originally Posted by Old Pedant View Post
Also, in the query you showed, you were *NOT* testing for a blank string.

You were testing for a string with ONE SPACE in it.

And that is a very very different thing.


... AND cookies=' '

See the space in there? That would *ONLY* match a field that indeed had a single space stored in it.
Ah yeah ok ... i understand. Thx guys that was a very usefull thing what you explained me right now :P Thx and... if u would have time check this please :/

http://www.codingforums.com/showthread.php?t=248566
Trki is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:37 AM.


Advertisement
Log in to turn off these ads.