Adding upstream version 25.1.0.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
91ffc387a9
commit
147b6e06e8
79 changed files with 28803 additions and 24929 deletions
|
@ -8,6 +8,7 @@ from sqlglot.dialects.dialect import (
|
|||
Dialect,
|
||||
JSON_EXTRACT_TYPE,
|
||||
any_value_to_max_sql,
|
||||
binary_from_function,
|
||||
bool_xor_sql,
|
||||
datestrtodate_sql,
|
||||
build_formatted_time,
|
||||
|
@ -25,6 +26,7 @@ from sqlglot.dialects.dialect import (
|
|||
build_json_extract_path,
|
||||
build_timestamp_trunc,
|
||||
rename_func,
|
||||
sha256_sql,
|
||||
str_position_sql,
|
||||
struct_extract_sql,
|
||||
timestamptrunc_sql,
|
||||
|
@ -329,6 +331,7 @@ class Postgres(Dialect):
|
|||
"REGTYPE": TokenType.OBJECT_IDENTIFIER,
|
||||
"FLOAT": TokenType.DOUBLE,
|
||||
}
|
||||
KEYWORDS.pop("DIV")
|
||||
|
||||
SINGLE_TOKENS = {
|
||||
**tokens.Tokenizer.SINGLE_TOKENS,
|
||||
|
@ -347,6 +350,9 @@ class Postgres(Dialect):
|
|||
FUNCTIONS = {
|
||||
**parser.Parser.FUNCTIONS,
|
||||
"DATE_TRUNC": build_timestamp_trunc,
|
||||
"DIV": lambda args: exp.cast(
|
||||
binary_from_function(exp.IntDiv)(args), exp.DataType.Type.DECIMAL
|
||||
),
|
||||
"GENERATE_SERIES": _build_generate_series,
|
||||
"JSON_EXTRACT_PATH": build_json_extract_path(exp.JSONExtract),
|
||||
"JSON_EXTRACT_PATH_TEXT": build_json_extract_path(exp.JSONExtractScalar),
|
||||
|
@ -357,6 +363,9 @@ class Postgres(Dialect):
|
|||
"TO_CHAR": build_formatted_time(exp.TimeToStr, "postgres"),
|
||||
"TO_TIMESTAMP": _build_to_timestamp,
|
||||
"UNNEST": exp.Explode.from_arg_list,
|
||||
"SHA256": lambda args: exp.SHA2(this=seq_get(args, 0), length=exp.Literal.number(256)),
|
||||
"SHA384": lambda args: exp.SHA2(this=seq_get(args, 0), length=exp.Literal.number(384)),
|
||||
"SHA512": lambda args: exp.SHA2(this=seq_get(args, 0), length=exp.Literal.number(512)),
|
||||
}
|
||||
|
||||
FUNCTION_PARSERS = {
|
||||
|
@ -494,6 +503,7 @@ class Postgres(Dialect):
|
|||
exp.DateSub: _date_add_sql("-"),
|
||||
exp.Explode: rename_func("UNNEST"),
|
||||
exp.GroupConcat: _string_agg_sql,
|
||||
exp.IntDiv: rename_func("DIV"),
|
||||
exp.JSONExtract: _json_extract_sql("JSON_EXTRACT_PATH", "->"),
|
||||
exp.JSONExtractScalar: _json_extract_sql("JSON_EXTRACT_PATH_TEXT", "->>"),
|
||||
exp.JSONBExtract: lambda self, e: self.binary(e, "#>"),
|
||||
|
@ -528,6 +538,7 @@ class Postgres(Dialect):
|
|||
transforms.eliminate_qualify,
|
||||
]
|
||||
),
|
||||
exp.SHA2: sha256_sql,
|
||||
exp.StrPosition: str_position_sql,
|
||||
exp.StrToDate: lambda self, e: self.func("TO_DATE", e.this, self.format_time(e)),
|
||||
exp.StrToTime: lambda self, e: self.func("TO_TIMESTAMP", e.this, self.format_time(e)),
|
||||
|
@ -621,3 +632,12 @@ class Postgres(Dialect):
|
|||
return f"{self.expressions(expression, flat=True)}[{values}]"
|
||||
return "ARRAY"
|
||||
return super().datatype_sql(expression)
|
||||
|
||||
def cast_sql(self, expression: exp.Cast, safe_prefix: t.Optional[str] = None) -> str:
|
||||
this = expression.this
|
||||
|
||||
# Postgres casts DIV() to decimal for transpilation but when roundtripping it's superfluous
|
||||
if isinstance(this, exp.IntDiv) and expression.to == exp.DataType.build("decimal"):
|
||||
return self.sql(this)
|
||||
|
||||
return super().cast_sql(expression, safe_prefix=safe_prefix)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue