diff options
Diffstat (limited to 'sqlglot/dialects/redshift.py')
-rw-r--r-- | sqlglot/dialects/redshift.py | 41 |
1 files changed, 6 insertions, 35 deletions
diff --git a/sqlglot/dialects/redshift.py b/sqlglot/dialects/redshift.py index 09edd55..f687ba7 100644 --- a/sqlglot/dialects/redshift.py +++ b/sqlglot/dialects/redshift.py @@ -27,6 +27,11 @@ class Redshift(Postgres): class Parser(Postgres.Parser): FUNCTIONS = { **Postgres.Parser.FUNCTIONS, + "ADD_MONTHS": lambda args: exp.DateAdd( + this=exp.TsOrDsToDate(this=seq_get(args, 0)), + expression=seq_get(args, 1), + unit=exp.var("month"), + ), "DATEADD": lambda args: exp.DateAdd( this=exp.TsOrDsToDate(this=seq_get(args, 2)), expression=seq_get(args, 1), @@ -37,7 +42,6 @@ class Redshift(Postgres): expression=exp.TsOrDsToDate(this=seq_get(args, 1)), unit=seq_get(args, 0), ), - "NVL": exp.Coalesce.from_arg_list, "STRTOL": exp.FromBase.from_arg_list, } @@ -87,6 +91,7 @@ class Redshift(Postgres): LOCKING_READS_SUPPORTED = False RENAME_TABLE_WITH_DB = False QUERY_HINTS = False + VALUES_AS_TABLE = False TYPE_MAPPING = { **Postgres.Generator.TYPE_MAPPING, @@ -129,40 +134,6 @@ class Redshift(Postgres): RESERVED_KEYWORDS = {*Postgres.Generator.RESERVED_KEYWORDS, "snapshot", "type"} - def values_sql(self, expression: exp.Values) -> str: - """ - Converts `VALUES...` expression into a series of unions. - - Note: If you have a lot of unions then this will result in a large number of recursive statements to - evaluate the expression. You may need to increase `sys.setrecursionlimit` to run and it can also be - very slow. - """ - - # The VALUES clause is still valid in an `INSERT INTO ..` statement, for example - if not expression.find_ancestor(exp.From, exp.Join): - return super().values_sql(expression) - - column_names = expression.alias and expression.args["alias"].columns - - selects = [] - rows = [tuple_exp.expressions for tuple_exp in expression.expressions] - - for i, row in enumerate(rows): - if i == 0 and column_names: - row = [ - exp.alias_(value, column_name) - for value, column_name in zip(row, column_names) - ] - - selects.append(exp.Select(expressions=row)) - - subquery_expression: exp.Select | exp.Union = selects[0] - if len(selects) > 1: - for select in selects[1:]: - subquery_expression = exp.union(subquery_expression, select, distinct=False) - - return self.subquery_sql(subquery_expression.subquery(expression.alias)) - def with_properties(self, properties: exp.Properties) -> str: """Redshift doesn't have `WITH` as part of their with_properties so we remove it""" return self.properties(properties, prefix=" ", suffix="") |