Bug #3119 LPAD broken when string is exactly pad length
Submitted: 9 Mar 2004 10:05 Modified: 9 Mar 2004 10:13
Reporter: Jeremy Cole (Basic Quality Contributor) (OCA) Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:4.1.1, 4.1.1a OS:Any (All)
Assigned to: Assigned Account CPU Architecture:Any

[9 Mar 2004 10:05] Jeremy Cole
Description:
LPAD(string, length, pad)

When the length argument to LPAD is exactly the same as the "string" length, the return value gets corrupted.

How to repeat:
When the contents is exactly the same length as the pad length, on Linux I get a blank:

mysql> select lpad(1277558000, 10, "a");
+---------------------------+
| lpad(1277558000, 10, "a") |
+---------------------------+
|                           |
+---------------------------+

On Windows I get garbage:

mysql> select lpad(1277558000, 10, "a");
+---------------------------+
| lpad(1277558000, 10, "a") |
+---------------------------+
| ê╙♥☺558000                |
+---------------------------+

LPAD works correctly if the length is more than the minimum:

mysql> select lpad(1277558000, 11, "a");
+---------------------------+
| lpad(1277558000, 11, "a") |
+---------------------------+
| a1277558000               |
+---------------------------+

Suggested fix:
--work-properly flag :)
[9 Mar 2004 10:13] Dean Ellis
Duplicate of 2182 (fixed in 4.1.2).