Merging upstream version 11.4.1.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
ecb42ec17f
commit
63746a3e92
89 changed files with 35352 additions and 33081 deletions
|
@ -12,6 +12,7 @@ from sqlglot.dialects.dialect import (
|
|||
no_trycast_sql,
|
||||
rename_func,
|
||||
str_position_sql,
|
||||
timestamptrunc_sql,
|
||||
trim_sql,
|
||||
)
|
||||
from sqlglot.helper import seq_get
|
||||
|
@ -34,7 +35,7 @@ def _date_add_sql(kind):
|
|||
from sqlglot.optimizer.simplify import simplify
|
||||
|
||||
this = self.sql(expression, "this")
|
||||
unit = self.sql(expression, "unit")
|
||||
unit = expression.args.get("unit")
|
||||
expression = simplify(expression.args["expression"])
|
||||
|
||||
if not isinstance(expression, exp.Literal):
|
||||
|
@ -92,8 +93,7 @@ def _string_agg_sql(self, expression):
|
|||
this = expression.this
|
||||
if isinstance(this, exp.Order):
|
||||
if this.this:
|
||||
this = this.this
|
||||
this.pop()
|
||||
this = this.this.pop()
|
||||
order = self.sql(expression.this) # Order has a leading space
|
||||
|
||||
return f"STRING_AGG({self.format_args(this, separator)}{order})"
|
||||
|
@ -256,6 +256,9 @@ class Postgres(Dialect):
|
|||
"TO_TIMESTAMP": _to_timestamp,
|
||||
"TO_CHAR": format_time_lambda(exp.TimeToStr, "postgres"),
|
||||
"GENERATE_SERIES": _generate_series,
|
||||
"DATE_TRUNC": lambda args: exp.TimestampTrunc(
|
||||
this=seq_get(args, 1), unit=seq_get(args, 0)
|
||||
),
|
||||
}
|
||||
|
||||
BITWISE = {
|
||||
|
@ -311,6 +314,7 @@ class Postgres(Dialect):
|
|||
exp.DateSub: _date_add_sql("-"),
|
||||
exp.DateDiff: _date_diff_sql,
|
||||
exp.LogicalOr: rename_func("BOOL_OR"),
|
||||
exp.LogicalAnd: rename_func("BOOL_AND"),
|
||||
exp.Min: min_or_least,
|
||||
exp.ArrayOverlaps: lambda self, e: self.binary(e, "&&"),
|
||||
exp.ArrayContains: lambda self, e: self.binary(e, "@>"),
|
||||
|
@ -320,6 +324,7 @@ class Postgres(Dialect):
|
|||
exp.StrPosition: str_position_sql,
|
||||
exp.StrToTime: lambda self, e: f"TO_TIMESTAMP({self.sql(e, 'this')}, {self.format_time(e)})",
|
||||
exp.Substring: _substring_sql,
|
||||
exp.TimestampTrunc: timestamptrunc_sql,
|
||||
exp.TimeStrToTime: lambda self, e: f"CAST({self.sql(e, 'this')} AS TIMESTAMP)",
|
||||
exp.TimeToStr: lambda self, e: f"TO_CHAR({self.sql(e, 'this')}, {self.format_time(e)})",
|
||||
exp.TableSample: no_tablesample_sql,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue