summaryrefslogtreecommitdiffstats
path: root/sqlglot/dialects/duckdb.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-08-14 10:12:19 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-08-14 10:12:19 +0000
commit3742f86d166160ca3843872ebecb6f30c51f6085 (patch)
tree6d747c3e7082fc2bae56053930813d5625e9b3d8 /sqlglot/dialects/duckdb.py
parentReleasing debian version 17.11.0-1. (diff)
downloadsqlglot-3742f86d166160ca3843872ebecb6f30c51f6085.tar.xz
sqlglot-3742f86d166160ca3843872ebecb6f30c51f6085.zip
Merging upstream version 17.12.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'sqlglot/dialects/duckdb.py')
-rw-r--r--sqlglot/dialects/duckdb.py26
1 files changed, 24 insertions, 2 deletions
diff --git a/sqlglot/dialects/duckdb.py b/sqlglot/dialects/duckdb.py
index 5428e86..8253b52 100644
--- a/sqlglot/dialects/duckdb.py
+++ b/sqlglot/dialects/duckdb.py
@@ -89,6 +89,11 @@ def _struct_sql(self: generator.Generator, expression: exp.Struct) -> str:
def _datatype_sql(self: generator.Generator, expression: exp.DataType) -> str:
if expression.is_type("array"):
return f"{self.expressions(expression, flat=True)}[]"
+
+ # Type TIMESTAMP / TIME WITH TIME ZONE does not support any modifiers
+ if expression.is_type("timestamptz", "timetz"):
+ return expression.this.value
+
return self.datatype_sql(expression)
@@ -110,14 +115,14 @@ class DuckDB(Dialect):
"//": TokenType.DIV,
"ATTACH": TokenType.COMMAND,
"BINARY": TokenType.VARBINARY,
- "BPCHAR": TokenType.TEXT,
"BITSTRING": TokenType.BIT,
+ "BPCHAR": TokenType.TEXT,
"CHAR": TokenType.TEXT,
"CHARACTER VARYING": TokenType.TEXT,
"EXCLUDE": TokenType.EXCEPT,
+ "HUGEINT": TokenType.INT128,
"INT1": TokenType.TINYINT,
"LOGICAL": TokenType.BOOLEAN,
- "NUMERIC": TokenType.DOUBLE,
"PIVOT_WIDER": TokenType.PIVOT,
"SIGNED": TokenType.INT,
"STRING": TokenType.VARCHAR,
@@ -186,6 +191,22 @@ class DuckDB(Dialect):
TokenType.UTINYINT,
}
+ def _parse_types(
+ self, check_func: bool = False, schema: bool = False
+ ) -> t.Optional[exp.Expression]:
+ this = super()._parse_types(check_func=check_func, schema=schema)
+
+ # DuckDB treats NUMERIC and DECIMAL without precision as DECIMAL(18, 3)
+ # See: https://duckdb.org/docs/sql/data_types/numeric
+ if (
+ isinstance(this, exp.DataType)
+ and this.is_type("numeric", "decimal")
+ and not this.expressions
+ ):
+ return exp.DataType.build("DECIMAL(18, 3)")
+
+ return this
+
def _pivot_column_names(self, aggregations: t.List[exp.Expression]) -> t.List[str]:
if len(aggregations) == 1:
return super()._pivot_column_names(aggregations)
@@ -231,6 +252,7 @@ class DuckDB(Dialect):
exp.Encode: lambda self, e: encode_decode_sql(self, e, "ENCODE", replace=False),
exp.Explode: rename_func("UNNEST"),
exp.IntDiv: lambda self, e: self.binary(e, "//"),
+ exp.IsNan: rename_func("ISNAN"),
exp.JSONExtract: arrow_json_extract_sql,
exp.JSONExtractScalar: arrow_json_extract_scalar_sql,
exp.JSONFormat: _json_format_sql,