Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
firebird-automations opened this issue Nov 11, 2009 · 6 comments

Comments

@firebird-automations
Copy link
Collaborator

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
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant