@@ -655,26 +655,6 @@ 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-
678658def _datatype_sql (self : DuckDBGenerator , expression : exp .DataType ) -> str :
679659 if expression .is_type ("array" ):
680660 return f"{ self .expressions (expression , flat = True )} [{ self .expressions (expression , key = 'values' , flat = True )} ]"
@@ -683,9 +663,6 @@ def _datatype_sql(self: DuckDBGenerator, expression: exp.DataType) -> str:
683663 if expression .is_type (exp .DType .TIME , exp .DType .TIMETZ , exp .DType .TIMESTAMPTZ ):
684664 return expression .this .value
685665
686- if expression .is_type (exp .DType .BIGDECIMAL ):
687- return _big_decimal_sql (self , expression )
688-
689666 return self .datatype_sql (expression )
690667
691668
@@ -1750,7 +1727,7 @@ class DuckDBGenerator(generator.Generator):
17501727 exp .DType .BPCHAR : "TEXT" ,
17511728 exp .DType .CHAR : "TEXT" ,
17521729 exp .DType .DATETIME : "TIMESTAMP" ,
1753- exp .DType .DECFLOAT : "DECIMAL(38, 5) " ,
1730+ exp .DType .DECFLOAT : "DECIMAL" ,
17541731 exp .DType .FLOAT : "REAL" ,
17551732 exp .DType .JSONB : "JSON" ,
17561733 exp .DType .NCHAR : "TEXT" ,
@@ -1767,6 +1744,18 @@ class DuckDBGenerator(generator.Generator):
17671744 exp .DType .BIGDECIMAL : "DECIMAL" ,
17681745 }
17691746
1747+ TYPE_DEFAULT_PARAMS = {
1748+ ** generator .Generator .TYPE_DEFAULT_PARAMS ,
1749+ exp .DType .BIGDECIMAL : (38 , 5 ),
1750+ exp .DType .DECFLOAT : (38 , 5 ),
1751+ }
1752+
1753+ TYPE_PARAM_BOUNDS = {
1754+ ** generator .Generator .TYPE_PARAM_BOUNDS ,
1755+ exp .DType .BIGDECIMAL : (38 , 38 ),
1756+ exp .DType .DECFLOAT : (38 , 38 ),
1757+ }
1758+
17701759 # https://github.com/duckdb/duckdb/blob/ff7f24fd8e3128d94371827523dae85ebaf58713/third_party/libpg_query/grammar/keywords/reserved_keywords.list#L1-L77
17711760 RESERVED_KEYWORDS = {
17721761 "array" ,
0 commit comments