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

fix: Parse LTRIM/RTRIM functions as positional exp.Trim #3958

Merged
merged 2 commits into from
Aug 23, 2024

Conversation

VaggelisD
Copy link
Collaborator

@georgesittas georgesittas merged commit cc29921 into main Aug 23, 2024
6 checks passed
@georgesittas georgesittas deleted the vaggelisd/trim branch August 23, 2024 09:58
@cpcloud
Copy link
Contributor

cpcloud commented Aug 27, 2024

This PR seems to have broken LTRIM and RTRIM that strip multiple characters in Oracle.

TRIM doesn't allow multiple characters, but LTRIM and RTRIM do.

Unfortunately the docs don't state this requirement explicitly anywhere: https://docs.oracle.com/en/database/oracle/oracle-database/23/sqlrf/TRIM.html#GUID-00D5C77C-19B1-4894-828F-066746235B03

If you try to run any TRIM call with more than one trim character then you'll get this error message:

E   oracledb.exceptions.DatabaseError: ORA-30001: trim set should have only one character
E   Help: https://docs.oracle.com/error-help/db/ora-30001/

@VaggelisD
Copy link
Collaborator Author

VaggelisD commented Aug 27, 2024

That checks out:

SELECT TRIM(LEADING 'ab' FROM 'abc')
       *
ERROR at line 1:
ORA-30001: trim set should have only one character

vs

SELECT LTRIM('abc', 'ab');
'c'

Also relevant SO thread.

So for Oracle, we can probably do the following:

  • If we have LEADING or TRAILING positional specifiers and multiple remove characters, we should force LTRIM and RTRIM generation respectively
  • For other cases (e.g. BOTH specifier, 0 or 1 remove chars) we can keep the existing representation: TRIM(<position> <remove char> FROM <string>

@georgesittas
Copy link
Collaborator

Let's just keep it simple and always do LTRIM and RTRIM for LEADING and TRAILING, respectively. No need to make it complicated.

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

Successfully merging this pull request may close these issues.

Failed to transpile Oracle rtrim/ltrim to ClickHouse
3 participants