summaryrefslogtreecommitdiffstats
path: root/sqlglot/expressions.py
diff options
context:
space:
mode:
Diffstat (limited to 'sqlglot/expressions.py')
-rw-r--r--sqlglot/expressions.py68
1 files changed, 57 insertions, 11 deletions
diff --git a/sqlglot/expressions.py b/sqlglot/expressions.py
index d093e29..be99fe2 100644
--- a/sqlglot/expressions.py
+++ b/sqlglot/expressions.py
@@ -653,6 +653,7 @@ class Create(Expression):
"statistics": False,
"no_primary_index": False,
"indexes": False,
+ "no_schema_binding": False,
}
@@ -770,6 +771,10 @@ class AlterColumn(Expression):
}
+class RenameTable(Expression):
+ pass
+
+
class ColumnConstraint(Expression):
arg_types = {"this": False, "kind": True}
@@ -804,7 +809,7 @@ class EncodeColumnConstraint(ColumnConstraintKind):
class GeneratedAsIdentityColumnConstraint(ColumnConstraintKind):
# this: True -> ALWAYS, this: False -> BY DEFAULT
- arg_types = {"this": True, "expression": False}
+ arg_types = {"this": True, "start": False, "increment": False}
class NotNullColumnConstraint(ColumnConstraintKind):
@@ -1266,7 +1271,7 @@ class Tuple(Expression):
class Subqueryable(Unionable):
- def subquery(self, alias=None, copy=True):
+ def subquery(self, alias=None, copy=True) -> Subquery:
"""
Convert this expression to an aliased expression that can be used as a Subquery.
@@ -1460,6 +1465,7 @@ class Unnest(UDTF):
"expressions": True,
"ordinality": False,
"alias": False,
+ "offset": False,
}
@@ -2126,6 +2132,7 @@ class DataType(Expression):
"this": True,
"expressions": False,
"nested": False,
+ "values": False,
}
class Type(AutoName):
@@ -2134,6 +2141,8 @@ class DataType(Expression):
VARCHAR = auto()
NVARCHAR = auto()
TEXT = auto()
+ MEDIUMTEXT = auto()
+ LONGTEXT = auto()
BINARY = auto()
VARBINARY = auto()
INT = auto()
@@ -2791,7 +2800,7 @@ class Day(Func):
class Decode(Func):
- arg_types = {"this": True, "charset": True}
+ arg_types = {"this": True, "charset": True, "replace": False}
class DiToDate(Func):
@@ -2815,7 +2824,7 @@ class Floor(Func):
class Greatest(Func):
- arg_types = {"this": True, "expressions": True}
+ arg_types = {"this": True, "expressions": False}
is_var_len_args = True
@@ -2861,7 +2870,7 @@ class JSONBExtractScalar(JSONExtract):
class Least(Func):
- arg_types = {"this": True, "expressions": True}
+ arg_types = {"this": True, "expressions": False}
is_var_len_args = True
@@ -2904,7 +2913,7 @@ class Lower(Func):
class Map(Func):
- arg_types = {"keys": True, "values": True}
+ arg_types = {"keys": False, "values": False}
class VarMap(Func):
@@ -2923,11 +2932,11 @@ class Matches(Func):
class Max(AggFunc):
- pass
+ arg_types = {"this": True, "expression": False}
class Min(AggFunc):
- pass
+ arg_types = {"this": True, "expression": False}
class Month(Func):
@@ -2962,7 +2971,7 @@ class QuantileIf(AggFunc):
class ApproxQuantile(Quantile):
- arg_types = {"this": True, "quantile": True, "accuracy": False}
+ arg_types = {"this": True, "quantile": True, "accuracy": False, "weight": False}
class ReadCSV(Func):
@@ -3022,7 +3031,12 @@ class Substring(Func):
class StrPosition(Func):
- arg_types = {"substr": True, "this": True, "position": False}
+ arg_types = {
+ "this": True,
+ "substr": True,
+ "position": False,
+ "instance": False,
+ }
class StrToDate(Func):
@@ -3129,8 +3143,10 @@ class UnixToStr(Func):
arg_types = {"this": True, "format": False}
+# https://prestodb.io/docs/current/functions/datetime.html
+# presto has weird zone/hours/minutes
class UnixToTime(Func):
- arg_types = {"this": True, "scale": False}
+ arg_types = {"this": True, "scale": False, "zone": False, "hours": False, "minutes": False}
SECONDS = Literal.string("seconds")
MILLIS = Literal.string("millis")
@@ -3684,6 +3700,16 @@ def to_identifier(alias, quoted=None) -> t.Optional[Identifier]:
return identifier
+@t.overload
+def to_table(sql_path: str | Table, **kwargs) -> Table:
+ ...
+
+
+@t.overload
+def to_table(sql_path: None, **kwargs) -> None:
+ ...
+
+
def to_table(sql_path: t.Optional[str | Table], **kwargs) -> t.Optional[Table]:
"""
Create a table expression from a `[catalog].[schema].[table]` sql path. Catalog and schema are optional.
@@ -3860,6 +3886,26 @@ def values(
)
+def rename_table(old_name: str | Table, new_name: str | Table) -> AlterTable:
+ """Build ALTER TABLE... RENAME... expression
+
+ Args:
+ old_name: The old name of the table
+ new_name: The new name of the table
+
+ Returns:
+ Alter table expression
+ """
+ old_table = to_table(old_name)
+ new_table = to_table(new_name)
+ return AlterTable(
+ this=old_table,
+ actions=[
+ RenameTable(this=new_table),
+ ],
+ )
+
+
def convert(value) -> Expression:
"""Convert a python value into an expression object.