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!: cast less aggressively #3302

Merged
merged 6 commits into from Apr 11, 2024
Merged

Fix!: cast less aggressively #3302

merged 6 commits into from Apr 11, 2024

Conversation

georgesittas
Copy link
Collaborator

This addresses the following issue (note the additional TIMESTAMP added):

>>> import sqlglot
>>> sql = "SELECT DATE_FORMAT(CAST(FROM_UTC_TIMESTAMP(foo::TIMESTAMP, 'America/Los_Angeles') AS TIMESTAMP), 'yyyy-MM-dd HH:mm:ss') AS foo FROM t"
>>> expr.sql("databricks")
"SELECT DATE_FORMAT(CAST(CAST(FROM_UTC_TIMESTAMP(CAST(foo AS TIMESTAMP), 'America/Los_Angeles') AS TIMESTAMP) AS TIMESTAMP), 'yyyy-MM-dd HH:mm:ss') AS foo FROM t"

@georgesittas
Copy link
Collaborator Author

Not sure if we want to do this at the exp.cast level instead of manually using cast_unless everywhere, wdyt @tobymao? I.e. replace cast with cast_unless.

@tobymao
Copy link
Owner

tobymao commented Apr 11, 2024

let's change the behavior of cast to be cast unless, and then allow for flags to 1. change the type, 2. allow users to add cast no matter what, so this is a breaking change to cast

let's delete cast unless

sqlglot/expressions.py Outdated Show resolved Hide resolved
sqlglot/expressions.py Outdated Show resolved Hide resolved
@tobymao
Copy link
Owner

tobymao commented Apr 11, 2024

this is a breaking change

@georgesittas georgesittas changed the title Fix: cast less aggressively Fix!: cast less aggressively Apr 11, 2024
@georgesittas georgesittas merged commit 75e0c69 into main Apr 11, 2024
5 checks passed
@georgesittas georgesittas deleted the jo/less_aggressive_casting branch April 11, 2024 21:32
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.

None yet

2 participants