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

feat: Divert cast of PostgreSQL decimal with scale>0 to to_char #721

Merged
merged 3 commits into from
Feb 13, 2023

Conversation

nj1973
Copy link
Contributor

@nj1973 nj1973 commented Feb 13, 2023

Example of PostgreSQL default CAST behaviour (note the unnecessary .00):

# SELECT CAST(CAST(100 AS DECIMAL(5,2)) AS VARCHAR(10));
 varchar
---------
 100.00

Most other engines would return a string of '100' from the above operation.

This change overrides the PostgreSQL cast() function in third_party/ibis/ibis_addon/operations.py. The new code diverts the operation to rtrim(to_char(),'.') for Decimal columns with a scale > 0. The example about then looks like this:

# SELECT RTRIM(TO_CHAR(CAST(100 AS DECIMAL(5,2)),'FM999.99'),'.');
 rtrim
-------
 100

@nj1973
Copy link
Contributor Author

nj1973 commented Feb 13, 2023

/gcbrun

@nj1973 nj1973 changed the title Feature/issue 685 postgresql decimal with scale feat: Divert cast of PostgreSQL decimal with scale>0 to to_char Feb 13, 2023
@nehanene15
Copy link
Collaborator

LGTM! This is great.

@nj1973 nj1973 merged commit 3542851 into develop Feb 13, 2023
@nj1973 nj1973 deleted the feature/issue-685-postgresql-decimal-with-scale branch February 13, 2023 17:38
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.

validate row: Oracle NUMBER with scale doesn't match PostgreSQL DECIMAL with scale
2 participants