Home » Performance » MySQL » Normal for mysql to strip trailing spaces?
Normal for mysql to strip trailing spaces? [message #425] Sun, 26 November 2006 01:47 Go to next message
carpii  is currently offline carpii
Messages: 48
Registered: November 2006
Member
I have a table users, with u_username field varchar(20)
Im using mysql v5

select u_userid from users where u_username = 'carpii'
returns user id 17

select u_userid from users where u_username = 'carpii '
also returns user id 17

Is this normal behavior for mysql?
Can it be changed?


Re: Normal for mysql to strip trailing spaces? [message #426 is a reply to message #425 ] Sun, 26 November 2006 10:29 Go to previous messageGo to next message
bitrockers  is currently offline bitrockers
Messages: 11
Registered: November 2006
Location: Germany
Junior Member
That's indeed weired.... we're using Mysql 5.0.19 and it's the same behaviour as you describe. That also happens on 5.0.22.

If you do the same query using like instead of =,

... where u_username like 'carpi '


it doesn't happen. I don't know if that is expected behaviour by ANSI standard or mysql.

Greetings
Christian

UPDATE: Guess its expected behaviour by ANSI-Standard. While looking in bugs.mysql.com I've found the following bug. At the end you can see a comment in the mysql source code, that says they 'have' to do it. Smile

http://bugs.mysql.com/bug.php?id=14637

[Updated on: Sun, 26 November 2006 10:48]

Re: Normal for mysql to strip trailing spaces? [message #427 is a reply to message #426 ] Mon, 27 November 2006 10:02 Go to previous message
Peter  is currently offline Peter
Messages: 405
Registered: August 2006
Senior Member
Super Guru
Yeah,

This is far from being obvious but this is how it is designed.

See: http://www.mysql.org/doc/refman/5.1/en/char.html


Peter Zaitsev, MySQL Performance Expert
MySQL Performance Blog - http://www.mysqlperformanceblog.com
MySQL Consulting http://www.mysqlperformanceblog.com/mysql-consulting/
Previous Topic:Slow connection to mysql
Next Topic:building new index on big tables
Goto Forum:
  


Current Time: Fri Jul 10 02:43:21 EDT 2009

Total time taken to generate the page: 0.10725 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 2.7.7.
Copyright ©2001-2007 FUD Forum Bulletin Board Software

MySQL is a trademark of Sun Microsystems.
InnoDB is a trademark of Oracle Corp.

Percona Performance Forums are a service of Percona, Inc.
Not affiliated with Sun Microsystems or Oracle Corp.