@@ -655,6 +655,26 @@ def _struct_sql(self: DuckDBGenerator, expression: exp.Struct) -> str:
655655 return f"ROW({ csv_args } )" if is_bq_inline_struct else f"{{{ csv_args } }}"
656656
657657
658+ def _big_decimal_sql (self : DuckDBGenerator , expression : exp .DataType ) -> str :
659+ if params := expression .expressions :
660+ precision_param = params [0 ].this if isinstance (params [0 ], exp .DataTypeParam ) else params [0 ]
661+ if (
662+ isinstance (precision_param , exp .Literal )
663+ and precision_param .is_number
664+ and int (precision_param .to_py ()) > 38
665+ ):
666+ self .unsupported (
667+ "DECIMAL precision exceeds maximum of 38 for DuckDB, capping to (38,5)"
668+ )
669+ expression = expression .copy ()
670+ expression .expressions [0 ].set ("this" , exp .Literal .number (38 ))
671+ expression .expressions [1 ].set ("this" , exp .Literal .number (5 ))
672+
673+ return f"DECIMAL({ self .expressions (expression , flat = True )} )"
674+
675+ return "DECIMAL(38, 5)"
676+
677+
658678def _datatype_sql (self : DuckDBGenerator , expression : exp .DataType ) -> str :
659679 if expression .is_type ("array" ):
660680 return f"{ self .expressions (expression , flat = True )} [{ self .expressions (expression , key = 'values' , flat = True )} ]"
@@ -663,9 +683,8 @@ def _datatype_sql(self: DuckDBGenerator, expression: exp.DataType) -> str:
663683 if expression .is_type (exp .DType .TIME , exp .DType .TIMETZ , exp .DType .TIMESTAMPTZ ):
664684 return expression .this .value
665685
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 )} )"
686+ if expression .is_type (exp .DType .BIGDECIMAL ):
687+ return _big_decimal_sql (self , expression )
669688
670689 return self .datatype_sql (expression )
671690
@@ -1745,7 +1764,7 @@ class DuckDBGenerator(generator.Generator):
17451764 exp .DType .TIMESTAMP_S : "TIMESTAMP_S" ,
17461765 exp .DType .TIMESTAMP_MS : "TIMESTAMP_MS" ,
17471766 exp .DType .TIMESTAMP_NS : "TIMESTAMP_NS" ,
1748- exp .DType .BIGDECIMAL : "DECIMAL(38, 5) " ,
1767+ exp .DType .BIGDECIMAL : "DECIMAL" ,
17491768 }
17501769
17511770 # https://github.com/duckdb/duckdb/blob/ff7f24fd8e3128d94371827523dae85ebaf58713/third_party/libpg_query/grammar/keywords/reserved_keywords.list#L1-L77
0 commit comments