summaryrefslogtreecommitdiffstats
path: root/sqlglot/dialects/presto.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-06-22 18:53:34 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-06-22 18:53:34 +0000
commit8f88a01462641cbf930b3c43b780565d0fb7d37e (patch)
treee211588c29e6ce6d16fbbfd33d8cda63237c2e6e /sqlglot/dialects/presto.py
parentReleasing debian version 16.2.1-1. (diff)
downloadsqlglot-8f88a01462641cbf930b3c43b780565d0fb7d37e.tar.xz
sqlglot-8f88a01462641cbf930b3c43b780565d0fb7d37e.zip
Merging upstream version 16.4.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'sqlglot/dialects/presto.py')
-rw-r--r--sqlglot/dialects/presto.py20
1 files changed, 8 insertions, 12 deletions
diff --git a/sqlglot/dialects/presto.py b/sqlglot/dialects/presto.py
index a8a9884..265780e 100644
--- a/sqlglot/dialects/presto.py
+++ b/sqlglot/dialects/presto.py
@@ -103,24 +103,15 @@ def _str_to_time_sql(
def _ts_or_ds_to_date_sql(self: generator.Generator, expression: exp.TsOrDsToDate) -> str:
time_format = self.format_time(expression)
if time_format and time_format not in (Presto.TIME_FORMAT, Presto.DATE_FORMAT):
- return f"CAST({_str_to_time_sql(self, expression)} AS DATE)"
- return f"CAST(SUBSTR(CAST({self.sql(expression, 'this')} AS VARCHAR), 1, 10) AS DATE)"
+ return exp.cast(_str_to_time_sql(self, expression), "DATE").sql(dialect="presto")
+ return exp.cast(exp.cast(expression.this, "TIMESTAMP"), "DATE").sql(dialect="presto")
def _ts_or_ds_add_sql(self: generator.Generator, expression: exp.TsOrDsAdd) -> str:
this = expression.this
if not isinstance(this, exp.CurrentDate):
- this = self.func(
- "DATE_PARSE",
- self.func(
- "SUBSTR",
- this if this.is_string else exp.cast(this, "VARCHAR"),
- exp.Literal.number(1),
- exp.Literal.number(10),
- ),
- Presto.DATE_FORMAT,
- )
+ this = exp.cast(exp.cast(expression.this, "TIMESTAMP"), "DATE")
return self.func(
"DATE_ADD",
@@ -181,6 +172,11 @@ class Presto(Dialect):
TIME_MAPPING = MySQL.TIME_MAPPING
STRICT_STRING_CONCAT = True
+ # https://github.com/trinodb/trino/issues/17
+ # https://github.com/trinodb/trino/issues/12289
+ # https://github.com/prestodb/presto/issues/2863
+ RESOLVES_IDENTIFIERS_AS_UPPERCASE = None
+
class Tokenizer(tokens.Tokenizer):
KEYWORDS = {
**tokens.Tokenizer.KEYWORDS,