List:General Discussion« Previous MessageNext Message »
From:Eric Bergen Date:April 18 2005 11:10pm
Subject:Re: 4==4something: equal vs identical
View as plain text  
The opposite of Paul's cast is:
select '4ae'f + 0;
That will show you what MySQL ends up with after casting a string to an integer.

-Eric

On 4/16/05, Paul DuBois <paul@stripped> wrote:
> At 22:18 +0200 4/16/05, Andy Pieters wrote:
> >Hi everone
> >
> >I ran into some situation where MySql selects a row by using the following
> >query:
> >
> >SELECT `id` FROM `shop_products` WHERE `id`="4aef" LIMIT 1;
> >+----+
> >| id |
> >+----+
> >|  4 |
> >+----+
> >
> >Granted the field IS of type int but 4 is not identical to 4aef (it may be
> >equal to the eyes of MySql)
> >
> >Isn't there an MySql equivalent of === (test for same+same type) or should I
> >just ignore this.
> 
> For a comparison of integer with string, the string is converted to number
> and a numeric comparison is done.  '4aef' converts to 4.
> 
> I suppose you could convert the integer to string instead:
> 
> WHERE CONCAT(`id`) = "4aef"
> 
> --
> Paul DuBois, MySQL Documentation Team
> Madison, Wisconsin, USA
> MySQL AB, www.mysql.com
> 
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:    http://lists.mysql.com/mysql?unsub=1
> 
> 


-- 
Eric Bergen
eric.bergen@stripped
http://www.ebergen.net
Thread
4==4something: equal vs identicalAndy Pieters16 Apr
  • Re: 4==4something: equal vs identicalPaul DuBois17 Apr
Re: 4==4something: equal vs identicalEric Bergen19 Apr