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(tsql): add support for DATETRUNC #4531 #4537

Merged
merged 4 commits into from
Dec 19, 2024

Conversation

geooo109
Copy link
Contributor

Fixes #4531

This PR adds support for the DATETRUNC function of T-SQL.

In cases, where the date parameter is a string literal, a casting is applied to produce a DATETIME2 expression.
Based on T-SQL, all string literals should resolve into DATETIME2.
Dialects like duckdb do not support the direct string literals as dates, thus the casting is mandatory.

Docs
T-SQL DATETRUNC

Copy link
Collaborator

@VaggelisD VaggelisD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! Left a few comments from my first pass:

sqlglot/dialects/tsql.py Outdated Show resolved Hide resolved
sqlglot/dialects/tsql.py Outdated Show resolved Hide resolved
sqlglot/dialects/tsql.py Outdated Show resolved Hide resolved
sqlglot/dialects/tsql.py Outdated Show resolved Hide resolved
sqlglot/dialects/tsql.py Outdated Show resolved Hide resolved
tests/dialects/test_tsql.py Show resolved Hide resolved
tests/dialects/test_tsql.py Outdated Show resolved Hide resolved
tests/dialects/test_tsql.py Outdated Show resolved Hide resolved
sqlglot/dialects/tsql.py Show resolved Hide resolved
Copy link
Collaborator

@georgesittas georgesittas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Copy link
Collaborator

@VaggelisD VaggelisD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, one final nit from my end

tests/dialects/test_tsql.py Show resolved Hide resolved
@georgesittas georgesittas merged commit 7fe9f7f into tobymao:main Dec 19, 2024
7 checks passed
@geooo109 geooo109 deleted the tsql_datetrunc branch December 20, 2024 00:12
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.

DATETRUNC not supported for dialect="tsql"
3 participants