From 98d5537435b2951b36c45f1fda667fa27c165794 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 3 May 2023 11:12:24 +0200 Subject: Adding upstream version 11.7.1. Signed-off-by: Daniel Baumann --- sqlglot/dialects/dialect.py | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) (limited to 'sqlglot/dialects/dialect.py') diff --git a/sqlglot/dialects/dialect.py b/sqlglot/dialects/dialect.py index 839589d..19c6f73 100644 --- a/sqlglot/dialects/dialect.py +++ b/sqlglot/dialects/dialect.py @@ -293,6 +293,13 @@ def no_properties_sql(self: Generator, expression: exp.Properties) -> str: return "" +def no_comment_column_constraint_sql( + self: Generator, expression: exp.CommentColumnConstraint +) -> str: + self.unsupported("CommentColumnConstraint unsupported") + return "" + + def str_position_sql(self: Generator, expression: exp.StrPosition) -> str: this = self.sql(expression, "this") substr = self.sql(expression, "substr") @@ -379,15 +386,35 @@ def parse_date_delta( ) -> t.Callable[[t.Sequence], E]: def inner_func(args: t.Sequence) -> E: unit_based = len(args) == 3 - this = seq_get(args, 2) if unit_based else seq_get(args, 0) - expression = seq_get(args, 1) if unit_based else seq_get(args, 1) - unit = seq_get(args, 0) if unit_based else exp.Literal.string("DAY") - unit = unit_mapping.get(unit.name.lower(), unit) if unit_mapping else unit # type: ignore - return exp_class(this=this, expression=expression, unit=unit) + this = args[2] if unit_based else seq_get(args, 0) + unit = args[0] if unit_based else exp.Literal.string("DAY") + unit = unit_mapping.get(unit.name.lower(), unit) if unit_mapping else unit + return exp_class(this=this, expression=seq_get(args, 1), unit=unit) return inner_func +def parse_date_delta_with_interval( + expression_class: t.Type[E], +) -> t.Callable[[t.Sequence], t.Optional[E]]: + def func(args: t.Sequence) -> t.Optional[E]: + if len(args) < 2: + return None + + interval = args[1] + expression = interval.this + if expression and expression.is_string: + expression = exp.Literal.number(expression.this) + + return expression_class( + this=args[0], + expression=expression, + unit=exp.Literal.string(interval.text("unit")), + ) + + return func + + def date_trunc_to_time(args: t.Sequence) -> exp.DateTrunc | exp.TimestampTrunc: unit = seq_get(args, 0) this = seq_get(args, 1) -- cgit v1.2.3