FirebirdSQL / firebird

Firebird server, client and tools
https://www.firebirdsql.org/
1.24k stars 212 forks source link

Build in function LPAD result is wrong if argument is longer then length to padd parameter [CORE2745] #3140

Open firebird-automations opened 14 years ago

firebird-automations commented 14 years ago

Submitted by: @livius2

select LPAD('123', 4, '0') FROM RDB$DATABASE result '0123' ok

select LPAD('1234', 4, '0') FROM RDB$DATABASE result '1234' ok

select LPAD('12345', 4, '0') FROM RDB$DATABASE result is 1234 - this is wrong

result in this situation should be '12345'

lpad should not change string if length is longer then length parameter

firebird-automations commented 14 years ago
Modified by: @livius2 Version: 2\.1\.3 \[ 10302 \] summary: LPAD work wrong if argument is longer then length parameter =\> LPAD work wrong if argument is longer then length to padd parameter
firebird-automations commented 14 years ago
Modified by: @livius2 description: select LPAD\('123', 4, '0'\) FROM RDB$DATABAS result '0123' ok select LPAD\('1234', 4, '0'\) FROM RDB$DATABAS result '1234' ok select LPAD\('12345', 4, '0'\) FROM RDB$DATABASE result is 1234 \- this is wrong result in this situation should be '12345' lpad should not change string if length is longer then length parameter =\> select LPAD\('123', 4, '0'\) FROM RDB$DATABASE result '0123' ok select LPAD\('1234', 4, '0'\) FROM RDB$DATABASE result '1234' ok select LPAD\('12345', 4, '0'\) FROM RDB$DATABASE result is 1234 \- this is wrong result in this situation should be '12345' lpad should not change string if length is longer then length parameter
firebird-automations commented 14 years ago
Modified by: @livius2 summary: LPAD work wrong if argument is longer then length to padd parameter =\> Build in function LPAD work wrong if argument is longer then length to padd parameter
firebird-automations commented 14 years ago

Commented by: Lester Caine (lsces)

http://www.firebirdsql.org/refdocs/langrefupd20-udf-lpad.html If endlength is less than str's length, str is truncated to endlength. If endlength is negative, the result is NULL. This is exactly the same as oracle, postgresql and mysql

firebird-automations commented 14 years ago
Modified by: @livius2 summary: Build in function LPAD work wrong if argument is longer then length to padd parameter =\> Build in function LPAD result is wrong if argument is longer then length to padd parameter
firebird-automations commented 14 years ago

Commented by: @livius2

if this is as designed then change description of this function because now is in README.builtin_functions.txt:

Function: LPAD(string1, length, string2) appends string2 to the beginning of string1 until length of the result string becomes equal to length.

Format: LPAD( <string>, <number> [, <string> ] )

Notes: 1) If the second string is omitted the default value is one space. 2) The second string is truncated when the result string will become larger than length.

Example: select lpad(x, 10) from y;

add in this description position: 3) If first string parameter is larger then number parameter then will be truncated

//#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠

and then i add new issue/new feature request to add some function like lpad and rpad without this limitation