diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2022-10-15 13:53:00 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2022-10-15 13:53:00 +0000 |
commit | 684905e3de7854a3806ffa55e0d1a09431ba5a19 (patch) | |
tree | 127ebd7d051f15fb8f8cf36cfd04a8a65a4d9680 /sqlglot/dialects/duckdb.py | |
parent | Releasing debian version 6.3.1-1. (diff) | |
download | sqlglot-684905e3de7854a3806ffa55e0d1a09431ba5a19.tar.xz sqlglot-684905e3de7854a3806ffa55e0d1a09431ba5a19.zip |
Merging upstream version 7.1.3.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'sqlglot/dialects/duckdb.py')
-rw-r--r-- | sqlglot/dialects/duckdb.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/sqlglot/dialects/duckdb.py b/sqlglot/dialects/duckdb.py index e09c3dd..f3ff6d3 100644 --- a/sqlglot/dialects/duckdb.py +++ b/sqlglot/dialects/duckdb.py @@ -6,6 +6,7 @@ from sqlglot.dialects.dialect import ( arrow_json_extract_sql, format_time_lambda, no_pivot_sql, + no_properties_sql, no_safe_divide_sql, no_tablesample_sql, rename_func, @@ -68,6 +69,12 @@ def _struct_pack_sql(self, expression): return f"STRUCT_PACK({', '.join(args)})" +def _datatype_sql(self, expression): + if expression.this == exp.DataType.Type.ARRAY: + return f"{self.expressions(expression, flat=True)}[]" + return self.datatype_sql(expression) + + class DuckDB(Dialect): class Tokenizer(Tokenizer): KEYWORDS = { @@ -106,6 +113,8 @@ class DuckDB(Dialect): } class Generator(Generator): + STRUCT_DELIMITER = ("(", ")") + TRANSFORMS = { **Generator.TRANSFORMS, exp.ApproxDistinct: approx_count_distinct_sql, @@ -113,8 +122,9 @@ class DuckDB(Dialect): exp.ArraySize: rename_func("ARRAY_LENGTH"), exp.ArraySort: _array_sort_sql, exp.ArraySum: rename_func("LIST_SUM"), + exp.DataType: _datatype_sql, exp.DateAdd: _date_add, - exp.DateDiff: lambda self, e: f"""DATE_DIFF({self.sql(e, 'unit') or "'day'"}, {self.sql(e, 'expression')}, {self.sql(e, 'this')})""", + exp.DateDiff: lambda self, e: f"""DATE_DIFF({self.format_args(e.args.get("unit") or "'day'", e.expression, e.this)})""", exp.DateStrToDate: lambda self, e: f"CAST({self.sql(e, 'this')} AS DATE)", exp.DateToDi: lambda self, e: f"CAST(STRFTIME({self.sql(e, 'this')}, {DuckDB.dateint_format}) AS INT)", exp.DiToDate: lambda self, e: f"CAST(STRPTIME(CAST({self.sql(e, 'this')} AS TEXT), {DuckDB.dateint_format}) AS DATE)", @@ -124,6 +134,7 @@ class DuckDB(Dialect): exp.JSONBExtract: arrow_json_extract_sql, exp.JSONBExtractScalar: arrow_json_extract_scalar_sql, exp.Pivot: no_pivot_sql, + exp.Properties: no_properties_sql, exp.RegexpLike: rename_func("REGEXP_MATCHES"), exp.RegexpSplit: rename_func("STR_SPLIT_REGEX"), exp.SafeDivide: no_safe_divide_sql, |