Bug #17753 Trailing spaces removed from CHAR stored procedure variables
Submitted: 27 Feb 2006 20:02 Modified: 16 Mar 2006 15:27
Reporter: Mark Leith Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: Stored Routines Severity:S2 (Serious)
Version:5.0.18 OS:Any (All)
Assigned to: Alexander Nozdrin CPU Architecture:Any

[27 Feb 2006 20:02] Mark Leith
Description:
CHAR variables within stored procedures now strip trailing spaces. VARCHAR variables do not strip trailing spaces however.

How to repeat:
CREATE PROCEDURE p1 ()
  BEGIN
  DECLARE a CHAR(3);
  DECLARE b VARCHAR(3);
  SET a = '12 ';
  SET b = '12 ';
  SELECT CONCAT('>',a,'<','>',b,'<');
END//

Result:

mysql> call p1()//
+-----------------------------+
| CONCAT('>',a,'<','>',b,'<') |
+-----------------------------+
| >12<>12 <                   |
+-----------------------------+

Suggested fix:
Preserve trailing spaces for CHAR variables
[16 Mar 2006 15:28] Alexander Nozdrin
The stored routine variables should behave like the table columns. As it is defined in
MySQL manual (http://dev.mysql.com/doc/refman/5.0/en/char.html) trailing spaces
are removed, when CHAR value is retrieved.