-
Notifications
You must be signed in to change notification settings - Fork 228
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
string.PadLeft and string.PadRight wrong translation #3116
Comments
@ozgur-yalcin sorry for not answering earlier, this is a very busy period. If the behavior discrepancy is when the string is longer, then we can continue to use lpad/rpad, but wrap it in a CASE/WHEN in the translation to simply return the original string when it's longer, i.e. @Voonti the point @ozgur-yalcin made above is that .NET's PadLeft and PG lpad don't behave the same way when the string a larger (i.e. PG truncates, .NET does nothing). |
@ozgur-yalcin if this sounds good, are you interested in submitting a PR to fix this? |
Sounds good, thanks for your support. |
@roji do you want a test for padleft/right for both with constant and with parameter to check that it doesn't truncate |
Npgsql EF Core provider automatically translates stringValue.PadLeft(length, char) -> lpad(stringValue, length, char).
However, these two functions do not produce exactly the same result and may cause problems.
C# example:
SQL example:
If the string is already longer than length then it is truncated in lpad and rpad functions.
lpad and rpad functions need to be replaced with a new function that gives the correct result.
I tried a method like the one below, but strangely, in a different scenario, I still did not get the result I expected.
SQL example:
After working on it a bit I found a method that works correctly as follows
Do you have any other ideas?
The text was updated successfully, but these errors were encountered: