Adding upstream version 26.8.0.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
4b797b16f0
commit
4c394df415
61 changed files with 43883 additions and 41898 deletions
|
@ -1238,8 +1238,10 @@ class Generator(metaclass=_Generator):
|
|||
if self.CTE_RECURSIVE_KEYWORD_REQUIRED and expression.args.get("recursive")
|
||||
else ""
|
||||
)
|
||||
search = self.sql(expression, "search")
|
||||
search = f" {search}" if search else ""
|
||||
|
||||
return f"WITH {recursive}{sql}"
|
||||
return f"WITH {recursive}{sql}{search}"
|
||||
|
||||
def cte_sql(self, expression: exp.CTE) -> str:
|
||||
alias = expression.args.get("alias")
|
||||
|
@ -1276,11 +1278,30 @@ class Generator(metaclass=_Generator):
|
|||
return f"{self.dialect.BIT_START}{this}{self.dialect.BIT_END}"
|
||||
return f"{int(this, 2)}"
|
||||
|
||||
def hexstring_sql(self, expression: exp.HexString) -> str:
|
||||
def hexstring_sql(
|
||||
self, expression: exp.HexString, binary_function_repr: t.Optional[str] = None
|
||||
) -> str:
|
||||
this = self.sql(expression, "this")
|
||||
if self.dialect.HEX_START:
|
||||
return f"{self.dialect.HEX_START}{this}{self.dialect.HEX_END}"
|
||||
return f"{int(this, 16)}"
|
||||
is_integer_type = expression.args.get("is_integer")
|
||||
|
||||
if (is_integer_type and not self.dialect.HEX_STRING_IS_INTEGER_TYPE) or (
|
||||
not self.dialect.HEX_START and not binary_function_repr
|
||||
):
|
||||
# Integer representation will be returned if:
|
||||
# - The read dialect treats the hex value as integer literal but not the write
|
||||
# - The transpilation is not supported (write dialect hasn't set HEX_START or the param flag)
|
||||
return f"{int(this, 16)}"
|
||||
|
||||
if not is_integer_type:
|
||||
# Read dialect treats the hex value as BINARY/BLOB
|
||||
if binary_function_repr:
|
||||
# The write dialect supports the transpilation to its equivalent BINARY/BLOB
|
||||
return self.func(binary_function_repr, exp.Literal.string(this))
|
||||
if self.dialect.HEX_STRING_IS_INTEGER_TYPE:
|
||||
# The write dialect does not support the transpilation, it'll treat the hex value as INTEGER
|
||||
self.unsupported("Unsupported transpilation from BINARY/BLOB hex string")
|
||||
|
||||
return f"{self.dialect.HEX_START}{this}{self.dialect.HEX_END}"
|
||||
|
||||
def bytestring_sql(self, expression: exp.ByteString) -> str:
|
||||
this = self.sql(expression, "this")
|
||||
|
@ -1467,10 +1488,17 @@ class Generator(metaclass=_Generator):
|
|||
direction = f" {direction}" if direction else ""
|
||||
count = self.sql(expression, "count")
|
||||
count = f" {count}" if count else ""
|
||||
if expression.args.get("percent"):
|
||||
count = f"{count} PERCENT"
|
||||
with_ties_or_only = "WITH TIES" if expression.args.get("with_ties") else "ONLY"
|
||||
return f"{self.seg('FETCH')}{direction}{count} ROWS {with_ties_or_only}"
|
||||
limit_options = self.sql(expression, "limit_options")
|
||||
limit_options = f"{limit_options}" if limit_options else " ROWS ONLY"
|
||||
return f"{self.seg('FETCH')}{direction}{count}{limit_options}"
|
||||
|
||||
def limitoptions_sql(self, expression: exp.LimitOptions) -> str:
|
||||
percent = " PERCENT" if expression.args.get("percent") else ""
|
||||
rows = " ROWS" if expression.args.get("rows") else ""
|
||||
with_ties = " WITH TIES" if expression.args.get("with_ties") else ""
|
||||
if not with_ties and rows:
|
||||
with_ties = " ONLY"
|
||||
return f"{percent}{rows}{with_ties}"
|
||||
|
||||
def filter_sql(self, expression: exp.Filter) -> str:
|
||||
if self.AGGREGATE_FILTER_SUPPORTED:
|
||||
|
@ -2261,9 +2289,10 @@ class Generator(metaclass=_Generator):
|
|||
args_sql = ", ".join(self.sql(e) for e in args)
|
||||
args_sql = f"({args_sql})" if top and any(not e.is_number for e in args) else args_sql
|
||||
expressions = self.expressions(expression, flat=True)
|
||||
limit_options = self.sql(expression, "limit_options")
|
||||
expressions = f" BY {expressions}" if expressions else ""
|
||||
|
||||
return f"{this}{self.seg('TOP' if top else 'LIMIT')} {args_sql}{expressions}"
|
||||
return f"{this}{self.seg('TOP' if top else 'LIMIT')} {args_sql}{limit_options}{expressions}"
|
||||
|
||||
def offset_sql(self, expression: exp.Offset) -> str:
|
||||
this = self.sql(expression, "this")
|
||||
|
@ -2284,9 +2313,7 @@ class Generator(metaclass=_Generator):
|
|||
return f"{global_}{kind}{this}{expressions}{collate}"
|
||||
|
||||
def set_sql(self, expression: exp.Set) -> str:
|
||||
expressions = (
|
||||
f" {self.expressions(expression, flat=True)}" if expression.expressions else ""
|
||||
)
|
||||
expressions = f" {self.expressions(expression, flat=True)}"
|
||||
tag = " TAG" if expression.args.get("tag") else ""
|
||||
return f"{'UNSET' if expression.args.get('unset') else 'SET'}{tag}{expressions}"
|
||||
|
||||
|
@ -3265,6 +3292,10 @@ class Generator(metaclass=_Generator):
|
|||
if comment:
|
||||
return f"ALTER COLUMN {this} COMMENT {comment}"
|
||||
|
||||
visible = expression.args.get("visible")
|
||||
if visible:
|
||||
return f"ALTER COLUMN {this} SET {visible}"
|
||||
|
||||
allow_null = expression.args.get("allow_null")
|
||||
drop = expression.args.get("drop")
|
||||
|
||||
|
@ -3277,6 +3308,14 @@ class Generator(metaclass=_Generator):
|
|||
|
||||
return f"ALTER COLUMN {this} DROP DEFAULT"
|
||||
|
||||
def alterindex_sql(self, expression: exp.AlterIndex) -> str:
|
||||
this = self.sql(expression, "this")
|
||||
|
||||
visible = expression.args.get("visible")
|
||||
visible_sql = "VISIBLE" if visible else "INVISIBLE"
|
||||
|
||||
return f"ALTER INDEX {this} {visible_sql}"
|
||||
|
||||
def alterdiststyle_sql(self, expression: exp.AlterDistStyle) -> str:
|
||||
this = self.sql(expression, "this")
|
||||
if not isinstance(expression.this, exp.Var):
|
||||
|
@ -3499,6 +3538,9 @@ class Generator(metaclass=_Generator):
|
|||
def trycast_sql(self, expression: exp.TryCast) -> str:
|
||||
return self.cast_sql(expression, safe_prefix="TRY_")
|
||||
|
||||
def jsoncast_sql(self, expression: exp.JSONCast) -> str:
|
||||
return self.cast_sql(expression)
|
||||
|
||||
def try_sql(self, expression: exp.Try) -> str:
|
||||
if not self.TRY_SUPPORTED:
|
||||
self.unsupported("Unsupported TRY function")
|
||||
|
@ -3523,7 +3565,7 @@ class Generator(metaclass=_Generator):
|
|||
def use_sql(self, expression: exp.Use) -> str:
|
||||
kind = self.sql(expression, "kind")
|
||||
kind = f" {kind}" if kind else ""
|
||||
this = self.sql(expression, "this")
|
||||
this = self.sql(expression, "this") or self.expressions(expression, flat=True)
|
||||
this = f" {this}" if this else ""
|
||||
return f"USE{kind}{this}"
|
||||
|
||||
|
@ -4762,3 +4804,45 @@ class Generator(metaclass=_Generator):
|
|||
connection = f"WITH CONNECTION {connection} " if connection else ""
|
||||
options = self.sql(expression, "options")
|
||||
return f"EXPORT DATA {connection}{options} AS {this}"
|
||||
|
||||
def declare_sql(self, expression: exp.Declare) -> str:
|
||||
return f"DECLARE {self.expressions(expression, flat=True)}"
|
||||
|
||||
def declareitem_sql(self, expression: exp.DeclareItem) -> str:
|
||||
variable = self.sql(expression, "this")
|
||||
default = self.sql(expression, "default")
|
||||
default = f" = {default}" if default else ""
|
||||
|
||||
kind = self.sql(expression, "kind")
|
||||
if isinstance(expression.args.get("kind"), exp.Schema):
|
||||
kind = f"TABLE {kind}"
|
||||
|
||||
return f"{variable} AS {kind}{default}"
|
||||
|
||||
def recursivewithsearch_sql(self, expression: exp.RecursiveWithSearch) -> str:
|
||||
kind = self.sql(expression, "kind")
|
||||
this = self.sql(expression, "this")
|
||||
set = self.sql(expression, "expression")
|
||||
using = self.sql(expression, "using")
|
||||
using = f" USING {using}" if using else ""
|
||||
|
||||
kind_sql = kind if kind == "CYCLE" else f"SEARCH {kind} FIRST BY"
|
||||
|
||||
return f"{kind_sql} {this} SET {set}{using}"
|
||||
|
||||
def parameterizedagg_sql(self, expression: exp.ParameterizedAgg) -> str:
|
||||
params = self.expressions(expression, key="params", flat=True)
|
||||
return self.func(expression.name, *expression.expressions) + f"({params})"
|
||||
|
||||
def anonymousaggfunc_sql(self, expression: exp.AnonymousAggFunc) -> str:
|
||||
return self.func(expression.name, *expression.expressions)
|
||||
|
||||
def combinedaggfunc_sql(self, expression: exp.CombinedAggFunc) -> str:
|
||||
return self.anonymousaggfunc_sql(expression)
|
||||
|
||||
def combinedparameterizedagg_sql(self, expression: exp.CombinedParameterizedAgg) -> str:
|
||||
return self.parameterizedagg_sql(expression)
|
||||
|
||||
def show_sql(self, expression: exp.Show) -> str:
|
||||
self.unsupported("Unsupported SHOW statement")
|
||||
return ""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue