diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-03-19 10:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-03-19 10:22:09 +0000 |
commit | 66af5c6fc22f6f11e9ea807b274e011a6f64efb7 (patch) | |
tree | 08ceed3b311b7b343935c1e55941b9d15e6f56d8 /sqlglot/dialects/redshift.py | |
parent | Releasing debian version 11.3.6-1. (diff) | |
download | sqlglot-66af5c6fc22f6f11e9ea807b274e011a6f64efb7.tar.xz sqlglot-66af5c6fc22f6f11e9ea807b274e011a6f64efb7.zip |
Merging upstream version 11.4.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'sqlglot/dialects/redshift.py')
-rw-r--r-- | sqlglot/dialects/redshift.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/sqlglot/dialects/redshift.py b/sqlglot/dialects/redshift.py index dc881b9..ebd5216 100644 --- a/sqlglot/dialects/redshift.py +++ b/sqlglot/dialects/redshift.py @@ -20,6 +20,11 @@ class Redshift(Postgres): class Parser(Postgres.Parser): FUNCTIONS = { **Postgres.Parser.FUNCTIONS, # type: ignore + "DATEADD": lambda args: exp.DateAdd( + this=seq_get(args, 2), + expression=seq_get(args, 1), + unit=seq_get(args, 0), + ), "DATEDIFF": lambda args: exp.DateDiff( this=seq_get(args, 2), expression=seq_get(args, 1), @@ -76,13 +81,16 @@ class Redshift(Postgres): TRANSFORMS = { **Postgres.Generator.TRANSFORMS, # type: ignore **transforms.ELIMINATE_DISTINCT_ON, # type: ignore + exp.DateAdd: lambda self, e: self.func( + "DATEADD", exp.var(e.text("unit") or "day"), e.expression, e.this + ), exp.DateDiff: lambda self, e: self.func( - "DATEDIFF", e.args.get("unit") or "day", e.expression, e.this + "DATEDIFF", exp.var(e.text("unit") or "day"), e.expression, e.this ), exp.DistKeyProperty: lambda self, e: f"DISTKEY({e.name})", - exp.SortKeyProperty: lambda self, e: f"{'COMPOUND ' if e.args['compound'] else ''}SORTKEY({self.format_args(*e.this)})", exp.DistStyleProperty: lambda self, e: self.naked_property(e), exp.Matches: rename_func("DECODE"), + exp.SortKeyProperty: lambda self, e: f"{'COMPOUND ' if e.args['compound'] else ''}SORTKEY({self.format_args(*e.this)})", } # Redshift uses the POW | POWER (expr1, expr2) syntax instead of expr1 ^ expr2 (postgres) |