1
0
Fork 0

Merging upstream version 9.0.3.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-13 14:50:31 +01:00
parent 66ef36a209
commit b1dc5c6faf
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
22 changed files with 742 additions and 223 deletions

View file

@ -2411,6 +2411,11 @@ class TimeTrunc(Func, TimeUnit):
arg_types = {"this": True, "unit": True, "zone": False}
class DateFromParts(Func):
_sql_names = ["DATEFROMPARTS"]
arg_types = {"year": True, "month": True, "day": True}
class DateStrToDate(Func):
pass
@ -2554,7 +2559,7 @@ class Quantile(AggFunc):
class ApproxQuantile(Quantile):
pass
arg_types = {"this": True, "quantile": True, "accuracy": False}
class Reduce(Func):
@ -2569,6 +2574,10 @@ class RegexpSplit(Func):
arg_types = {"this": True, "expression": True}
class Repeat(Func):
arg_types = {"this": True, "times": True}
class Round(Func):
arg_types = {"this": True, "decimals": False}
@ -2690,7 +2699,7 @@ class TsOrDiToDi(Func):
class UnixToStr(Func):
arg_types = {"this": True, "format": True}
arg_types = {"this": True, "format": False}
class UnixToTime(Func):
@ -3077,6 +3086,8 @@ def update(table, properties, where=None, from_=None, dialect=None, **opts):
)
if from_:
update.set("from", maybe_parse(from_, into=From, dialect=dialect, prefix="FROM", **opts))
if isinstance(where, Condition):
where = Where(this=where)
if where:
update.set("where", maybe_parse(where, into=Where, dialect=dialect, prefix="WHERE", **opts))
return update
@ -3518,6 +3529,41 @@ def replace_tables(expression, mapping):
return expression.transform(_replace_tables)
def replace_placeholders(expression, *args, **kwargs):
"""Replace placeholders in an expression.
Args:
expression (sqlglot.Expression): Expression node to be transformed and replaced
args: Positional names that will substitute unnamed placeholders in the given order
kwargs: Keyword arguments that will substitute named placeholders
Examples:
>>> from sqlglot import exp, parse_one
>>> replace_placeholders(
... parse_one("select * from :tbl where ? = ?"), "a", "b", tbl="foo"
... ).sql()
'SELECT * FROM foo WHERE a = b'
Returns:
The mapped expression
"""
def _replace_placeholders(node, args, **kwargs):
if isinstance(node, Placeholder):
if node.name:
new_name = kwargs.get(node.name)
if new_name:
return to_identifier(new_name)
else:
try:
return to_identifier(next(args))
except StopIteration:
pass
return node
return expression.transform(_replace_placeholders, iter(args), **kwargs)
TRUE = Boolean(this=True)
FALSE = Boolean(this=False)
NULL = Null()