Bug #117227 LPAD function false
Submitted: 17 Jan 16:36 Modified: 17 Jan 19:10
Reporter: RICHARD BUSKIRK Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Data Types Severity:S3 (Non-critical)
Version:8.0 OS:Linux
Assigned to: CPU Architecture:Any
Tags: lpad

[17 Jan 16:36] RICHARD BUSKIRK
Description:
The LPAD function does not return the correct value when given an empty string enclosed in double quotes, unless the string’s length exceeds the specified length variable.

Returning an empty value with a length of the length variable's value seems invalid. 

How to repeat:

MySQL [(none)]> SELECT LPAD("I LOVE SQL", 20, "");
+----------------------------+
| LPAD("I LOVE SQL", 20, "") |
+----------------------------+
|                            |
+----------------------------+

MySQL [(none)]> SELECT LPAD("I LOVE SQL IN THE MORNING", 20, "");
+-------------------------------------------+
| LPAD("I LOVE SQL IN THE MORNING", 20, "") |
+-------------------------------------------+
| I LOVE SQL IN THE MO                      |
+-------------------------------------------+

Suggested fix:

The function should return the same result as it does when the string’s length is not longer than the length variable, even if the string variable is declared as empty rather than NULL.
[17 Jan 19:10] MySQL Verification Team
HI Mr. Buskirk,

Thank you for your bug report.

This is truly a small and very low severity bug affecting 8.0 and all higher versions.

This bug also applies to RPAD.

Verified as reported.
[21 Jan 11:19] Tor Didriksen
Posted by developer:
 
both 5.6 and 5.7 return NULL

mysql> SELECT RPAD("I LOVE SQL", 20, "");
+----------------------------+
| RPAD("I LOVE SQL", 20, "") |
+----------------------------+
| NULL                       |
+----------------------------+
[21 Jan 11:25] MySQL Verification Team
Thank you, very much, Tor,

I agree that this is, possibly, the best behaviour.