summaryrefslogtreecommitdiffstats
path: root/sqlglot/dialects/redshift.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-10-10 08:53:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-10-10 08:53:14 +0000
commitcd37a3bcaced9283c20baa52837c96b524baec54 (patch)
tree101b1c1487aa832a982dd635cd3b00d4d2ea3ae9 /sqlglot/dialects/redshift.py
parentReleasing progress-linux version 18.11.2-1. (diff)
downloadsqlglot-cd37a3bcaced9283c20baa52837c96b524baec54.tar.xz
sqlglot-cd37a3bcaced9283c20baa52837c96b524baec54.zip
Merging upstream version 18.11.6.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'sqlglot/dialects/redshift.py')
-rw-r--r--sqlglot/dialects/redshift.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/sqlglot/dialects/redshift.py b/sqlglot/dialects/redshift.py
index 88e4448..b70a8a1 100644
--- a/sqlglot/dialects/redshift.py
+++ b/sqlglot/dialects/redshift.py
@@ -31,6 +31,7 @@ class Redshift(Postgres):
RESOLVES_IDENTIFIERS_AS_UPPERCASE = None
SUPPORTS_USER_DEFINED_TYPES = False
+ INDEX_OFFSET = 0
TIME_FORMAT = "'YYYY-MM-DD HH:MI:SS'"
TIME_MAPPING = {
@@ -57,6 +58,24 @@ class Redshift(Postgres):
"STRTOL": exp.FromBase.from_arg_list,
}
+ def _parse_table(
+ self,
+ schema: bool = False,
+ joins: bool = False,
+ alias_tokens: t.Optional[t.Collection[TokenType]] = None,
+ parse_bracket: bool = False,
+ ) -> t.Optional[exp.Expression]:
+ # Redshift supports UNPIVOTing SUPER objects, e.g. `UNPIVOT foo.obj[0] AS val AT attr`
+ unpivot = self._match(TokenType.UNPIVOT)
+ table = super()._parse_table(
+ schema=schema,
+ joins=joins,
+ alias_tokens=alias_tokens,
+ parse_bracket=parse_bracket,
+ )
+
+ return self.expression(exp.Pivot, this=table, unpivot=True) if unpivot else table
+
def _parse_types(
self, check_func: bool = False, schema: bool = False, allow_identifiers: bool = True
) -> t.Optional[exp.Expression]: