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

SQL Server Rowversion/Timestamp not parsed correctly #3345

Closed
aersam opened this issue Apr 24, 2024 · 1 comment · Fixed by #3348
Closed

SQL Server Rowversion/Timestamp not parsed correctly #3345

aersam opened this issue Apr 24, 2024 · 1 comment · Fixed by #3348
Assignees

Comments

@aersam
Copy link
Contributor

aersam commented Apr 24, 2024

In MS SQL Server, there is a funny type called rowversion and has an alias timestamp. It has nothing in common with timestamp types in other databases. It's basically an binary(8) type which stores an incrementing number

https://learn.microsoft.com/en-us/sql/t-sql/data-types/rowversion-transact-sql?view=sql-server-ver16

Sqlglot does not seem to recognize this type. It would be nice if sqlglot would transpile it correctly to binary types.

import sqlglot.expressions as ex
import sqlglot

print(  # transpiled type timestamp as is, should be binary
    sqlglot.parse_one("create table a (b timestamp)", dialect="tsql").sql("databricks")
)

print(  # prints ROWVERSION instead of BINARY
    sqlglot.parse_one("create table a (b rowversion)", dialect="tsql").sql("databricks")
)

print(  # good, this works! databricks timestamp is datetime2 in ms sql
    sqlglot.parse_one("create table a (b timestamp)", dialect="databricks").sql("tsql")
)
@VaggelisD VaggelisD self-assigned this Apr 24, 2024
@aersam
Copy link
Contributor Author

aersam commented Apr 24, 2024

one more interesting side-effect:

print(  
    sqlglot.parse_one("create table a (b timestamp)", dialect="tsql").sql("tsql")  # prints datetime2, which is completely wrong here
)

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 a pull request may close this issue.

2 participants