Bug #1109 data inserts improperly
Submitted: 20 Aug 2003 21:26 Modified: 21 Aug 2003 5:02
Reporter: Zak Kuhn Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S2 (Serious)
Version:4.1 alpha OS:FreeBSD (FreeBSD)
Assigned to: CPU Architecture:Any

[20 Aug 2003 21:26] Zak Kuhn
Description:
  Want to report a bug in Mysql 4.1 alpha.
    The problem is with inserting trailing spaces after an asterisk into
    a varchar field;
    Below is the create table statement, insert statement and select
    statement. I first ran across this using DBI in perl, then replicated it in the mysql command line client.
    
    

How to repeat:
  Want to report a bug in Mysql 4.1 alpha.
    The problem is with inserting trailing spaces after an asterisk into
    a varchar field;
    Below is the create table statement, insert statement and select
    statement. Sorry if this is the wrong method to contact you.
    
    
    
    mysql> show create table categories;
 
+------------+----------------------------------------------------------
------------------------------------------------------------------------
------------------------------------------------------------------------
------------------------------------------------------------------------
------------------------------------------------------------------------
------------------------------------------------------------------------
------------------------------------------------------------------------
--------------+
    | Table      | Create Table

 

 

 

 

 

 

                                |
 
+------------+----------------------------------------------------------
------------------------------------------------------------------------
------------------------------------------------------------------------
------------------------------------------------------------------------
------------------------------------------------------------------------
------------------------------------------------------------------------
------------------------------------------------------------------------
--------------+
    | categories | CREATE TABLE `categories` (
      `categories_id` int(11) NOT NULL auto_increment,
      `categories_image` varchar(64) default NULL,
      `parent_id` int(11) NOT NULL default '0',
      `sort_order` int(3) default NULL,
      `date_added` datetime default NULL,
      `last_modified` datetime default NULL,
      `ingram_cat_code` varchar(10) NOT NULL default '',
      `ingram_parent_cat` varchar(10) NOT NULL default '',
      PRIMARY KEY  (`categories_id`),
      KEY `idx_categories_parent_id` (`parent_id`)
    ) TYPE=MyISAM CHARSET=latin1 |
 
+------------+----------------------------------------------------------
------------------------------------------------------------------------
------------------------------------------------------------------------
------------------------------------------------------------------------
------------------------------------------------------------------------
------------------------------------------------------------------------
------------------------------------------------------------------------
--------------+
    1 row in set (0.00 sec)
    
    mysql> Insert into categories values('','','','','','','* ','00');
    Query OK, 1 row affected (0.00 sec)
    
    mysql> Select categories_id from categories where ingram_cat_code
    like '* ' AND ingram_parent_cat like '00';
    Empty set (0.00 sec)
[21 Aug 2003 5:02] Alexander Keremidarski
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.mysql.com/documentation/ and the instructions on
how to report a bug at http://bugs.mysql.com/how-to-report.php

From MySQL Manual: 
http://www.mysql.com/doc/en/CHAR.html

...

However, in contrast to CHAR, VARCHAR values are stored using only as many characters as are needed, plus one byte to record the length. Values are not padded; instead, trailing spaces are removed when values are stored. (This space removal differs from the SQL-99 specification.)

http://www.mysql.com/doc/en/Column_types.html
...
[NATIONAL] VARCHAR(M) [BINARY]
    A variable-length string. Note: trailing spaces are removed when the value is stored (this differs from the SQL-99 specification).