Skip to content

Commit fa5f99e

Browse files
added check for shift RHS to ensure it's an int
1 parent d2054f0 commit fa5f99e

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

sqlglot/dialects/duckdb.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ def _bitshift_sql(
718718
or (isinstance(this, exp.Cast) and _is_binary(this))
719719
)
720720

721-
# Deal with binary separately, remember the original type, cast back later, etc.
721+
# Deal with binary separately, remember the original type, cast back later
722722
if is_binary_input:
723723
original_type = this.to if isinstance(this, exp.Cast) else exp.DataType.build("BLOB")
724724

@@ -735,6 +735,11 @@ def _bitshift_sql(
735735
elif expression.args.get("requires_int128"):
736736
this.replace(exp.cast(this, exp.DataType.Type.INT128))
737737

738+
# Cast shift amount to int in case it's something else
739+
shift_amount = expression.expression
740+
if isinstance(shift_amount, exp.Literal) and not shift_amount.is_int:
741+
expression.set("expression", exp.cast(shift_amount, exp.DataType.Type.INT))
742+
738743
result_sql = self.binary(expression, operator)
739744

740745
# Wrap in parentheses if parent is a bitwise operator to "fix" DuckDB precedence issue

0 commit comments

Comments
 (0)