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

ex.convert(b"\x00\x00\x00\x00\x00\x00\x07\xd3") throws, but should be HexString #3195

Closed
aersam opened this issue Mar 22, 2024 · 2 comments · Fixed by #3198
Closed

ex.convert(b"\x00\x00\x00\x00\x00\x00\x07\xd3") throws, but should be HexString #3195

aersam opened this issue Mar 22, 2024 · 2 comments · Fixed by #3198

Comments

@aersam
Copy link

aersam commented Mar 22, 2024

The behavior of binary literal's is a bit weird currently:

import sqlglot.expressions as ex
import sqlglot as sg

print(
    repr(sg.parse_one("select 0x00000000000007d3", dialect="tsql"))
)  # binary literal in SQL Server
print(
    sg.parse_one("select 0x00000000000007d3", dialect="tsql").sql("duckdb")
)  # SELECT 2003 --> it's an int in duckdb, a bit unfortunate

import duckdb

duckdb.execute(
    "select '0x00000000000007d3'::blob"
).fetchall()  # correctly gives [(b'0x00000000000007d3',)]

ex.convert(
    b"\x00\x00\x00\x00\x00\x00\x07\xd3"
)  # should be ex.HexString(this="0x00000000000007d3"), I guess
# currently throws

Maybe a dedicated BinaryLiteral Type would be good? Not sure how to solve this :)

@georgesittas
Copy link
Collaborator

How would you go from b"\x00\x00\x00\x00\x00\x00\x07\xd3" to "0x00000000000007d3"?

@georgesittas
Copy link
Collaborator

I guess using something like "0x" + b"\x00\x00\x00\x00\x00\x00\x07\xd3".hex()?

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