Adding upstream version 23.16.0.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
9d7e0ff7aa
commit
b6ae88ec81
93 changed files with 64106 additions and 59061 deletions
|
@ -227,12 +227,27 @@ def _build_regexp_replace(args: t.List) -> exp.RegexpReplace:
|
|||
return exp.RegexpReplace.from_arg_list(args)
|
||||
|
||||
|
||||
def _unix_to_time_sql(self: Postgres.Generator, expression: exp.UnixToTime) -> str:
|
||||
scale = expression.args.get("scale")
|
||||
timestamp = expression.this
|
||||
|
||||
if scale in (None, exp.UnixToTime.SECONDS):
|
||||
return self.func("TO_TIMESTAMP", timestamp, self.format_time(expression))
|
||||
|
||||
return self.func(
|
||||
"TO_TIMESTAMP",
|
||||
exp.Div(this=timestamp, expression=exp.func("POW", 10, scale)),
|
||||
self.format_time(expression),
|
||||
)
|
||||
|
||||
|
||||
class Postgres(Dialect):
|
||||
INDEX_OFFSET = 1
|
||||
TYPED_DIVISION = True
|
||||
CONCAT_COALESCE = True
|
||||
NULL_ORDERING = "nulls_are_large"
|
||||
TIME_FORMAT = "'YYYY-MM-DD HH24:MI:SS'"
|
||||
TABLESAMPLE_SIZE_IS_PERCENT = True
|
||||
|
||||
TIME_MAPPING = {
|
||||
"AM": "%p",
|
||||
|
@ -528,7 +543,7 @@ class Postgres(Dialect):
|
|||
exp.Substring: _substring_sql,
|
||||
exp.TimeFromParts: rename_func("MAKE_TIME"),
|
||||
exp.TimestampFromParts: rename_func("MAKE_TIMESTAMP"),
|
||||
exp.TimestampTrunc: timestamptrunc_sql,
|
||||
exp.TimestampTrunc: timestamptrunc_sql(zone=True),
|
||||
exp.TimeStrToTime: timestrtotime_sql,
|
||||
exp.TimeToStr: lambda self, e: self.func("TO_CHAR", e.this, self.format_time(e)),
|
||||
exp.ToChar: lambda self, e: self.function_fallback_sql(e),
|
||||
|
@ -543,6 +558,7 @@ class Postgres(Dialect):
|
|||
exp.VariancePop: rename_func("VAR_POP"),
|
||||
exp.Variance: rename_func("VAR_SAMP"),
|
||||
exp.Xor: bool_xor_sql,
|
||||
exp.UnixToTime: _unix_to_time_sql,
|
||||
}
|
||||
TRANSFORMS.pop(exp.CommentColumnConstraint)
|
||||
|
||||
|
@ -593,3 +609,15 @@ class Postgres(Dialect):
|
|||
expressions = [f"{self.sql(e)} @@ {this}" for e in expression.expressions]
|
||||
sql = " OR ".join(expressions)
|
||||
return f"({sql})" if len(expressions) > 1 else sql
|
||||
|
||||
def alterset_sql(self, expression: exp.AlterSet) -> str:
|
||||
exprs = self.expressions(expression, flat=True)
|
||||
exprs = f"({exprs})" if exprs else ""
|
||||
|
||||
access_method = self.sql(expression, "access_method")
|
||||
access_method = f"ACCESS METHOD {access_method}" if access_method else ""
|
||||
tablespace = self.sql(expression, "tablespace")
|
||||
tablespace = f"TABLESPACE {tablespace}" if tablespace else ""
|
||||
option = self.sql(expression, "option")
|
||||
|
||||
return f"SET {exprs}{access_method}{tablespace}{option}"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue