summaryrefslogtreecommitdiffstats
path: root/sqlglot/dialects/redshift.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 05:35:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 05:35:55 +0000
commitfe979e8421c04c038353a0a2d07d81779516186a (patch)
treeefb70a52261e5cf4862a7eb69e1d7cd16356fcba /sqlglot/dialects/redshift.py
parentReleasing debian version 23.13.7-1. (diff)
downloadsqlglot-fe979e8421c04c038353a0a2d07d81779516186a.tar.xz
sqlglot-fe979e8421c04c038353a0a2d07d81779516186a.zip
Merging upstream version 23.16.0.
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, 15 insertions, 4 deletions
diff --git a/sqlglot/dialects/redshift.py b/sqlglot/dialects/redshift.py
index 651bf2b..d3388e7 100644
--- a/sqlglot/dialects/redshift.py
+++ b/sqlglot/dialects/redshift.py
@@ -39,6 +39,7 @@ class Redshift(Postgres):
SUPPORTS_USER_DEFINED_TYPES = False
INDEX_OFFSET = 0
COPY_PARAMS_ARE_CSV = False
+ HEX_LOWERCASE = True
TIME_FORMAT = "'YYYY-MM-DD HH:MI:SS'"
TIME_MAPPING = {
@@ -140,6 +141,9 @@ class Redshift(Postgres):
CAN_IMPLEMENT_ARRAY_ANY = False
MULTI_ARG_DISTINCT = True
COPY_PARAMS_ARE_WRAPPED = False
+ HEX_FUNC = "TO_HEX"
+ # Redshift doesn't have `WITH` as part of their with_properties so we remove it
+ WITH_PROPERTIES_PREFIX = " "
TYPE_MAPPING = {
**Postgres.Generator.TYPE_MAPPING,
@@ -169,6 +173,7 @@ class Redshift(Postgres):
exp.JSONExtract: json_extract_segments("JSON_EXTRACT_PATH_TEXT"),
exp.JSONExtractScalar: json_extract_segments("JSON_EXTRACT_PATH_TEXT"),
exp.GroupConcat: rename_func("LISTAGG"),
+ exp.Hex: lambda self, e: self.func("UPPER", self.func("TO_HEX", self.sql(e, "this"))),
exp.ParseJSON: rename_func("JSON_PARSE"),
exp.Select: transforms.preprocess(
[
@@ -372,10 +377,6 @@ class Redshift(Postgres):
alias = self.expressions(expression.args.get("alias"), key="columns", flat=True)
return f"{arg} AS {alias}" if alias else arg
- 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="")
-
def cast_sql(self, expression: exp.Cast, safe_prefix: t.Optional[str] = None) -> str:
if expression.is_type(exp.DataType.Type.JSON):
# Redshift doesn't support a JSON type, so casting to it is treated as a noop
@@ -398,3 +399,13 @@ class Redshift(Postgres):
expression.append("expressions", exp.var("MAX"))
return super().datatype_sql(expression)
+
+ def alterset_sql(self, expression: exp.AlterSet) -> str:
+ exprs = self.expressions(expression, flat=True)
+ exprs = f" TABLE PROPERTIES ({exprs})" if exprs else ""
+ location = self.sql(expression, "location")
+ location = f" LOCATION {location}" if location else ""
+ file_format = self.expressions(expression, key="file_format", flat=True, sep=" ")
+ file_format = f" FILE FORMAT {file_format}" if file_format else ""
+
+ return f"SET{exprs}{location}{file_format}"