Skip to content

Commit 3b8adea

Browse files
Fix: Parametrized bigdecimal mapping was being concatenated with params
1 parent fd48100 commit 3b8adea

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

sqlglot/generators/duckdb.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,10 @@ def _datatype_sql(self: DuckDBGenerator, expression: exp.DataType) -> str:
663663
if expression.is_type(exp.DType.TIME, exp.DType.TIMETZ, exp.DType.TIMESTAMPTZ):
664664
return expression.this.value
665665

666+
# BIGDECIMAL type maps to DECIMAL(38, 5) but we should pass through user params when provided
667+
if expression.is_type(exp.DType.BIGDECIMAL) and expression.expressions:
668+
return f"DECIMAL({self.expressions(expression, flat=True)})"
669+
666670
return self.datatype_sql(expression)
667671

668672

tests/dialects/test_bigquery.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3824,6 +3824,14 @@ def test_bignumeric(self):
38243824
},
38253825
)
38263826

3827+
self.validate_all(
3828+
f"DECLARE x {type_}(76, 38)",
3829+
write={
3830+
"bigquery": "DECLARE x BIGNUMERIC(76, 38)",
3831+
"duckdb": "DECLARE x DECIMAL(76, 38)",
3832+
},
3833+
)
3834+
38273835
self.validate_all(
38283836
f"SELECT CAST(1 AS {type_})",
38293837
write={

0 commit comments

Comments
 (0)