summaryrefslogtreecommitdiffstats
path: root/sqlglot/expressions.py
diff options
context:
space:
mode:
Diffstat (limited to 'sqlglot/expressions.py')
-rw-r--r--sqlglot/expressions.py26
1 files changed, 18 insertions, 8 deletions
diff --git a/sqlglot/expressions.py b/sqlglot/expressions.py
index f8e9fee..c207751 100644
--- a/sqlglot/expressions.py
+++ b/sqlglot/expressions.py
@@ -192,6 +192,13 @@ class Expression(metaclass=_Expression):
return self.text("alias")
@property
+ def alias_column_names(self) -> t.List[str]:
+ table_alias = self.args.get("alias")
+ if not table_alias:
+ return []
+ return [c.name for c in table_alias.args.get("columns") or []]
+
+ @property
def name(self) -> str:
return self.text("this")
@@ -884,13 +891,6 @@ class Predicate(Condition):
class DerivedTable(Expression):
@property
- def alias_column_names(self) -> t.List[str]:
- table_alias = self.args.get("alias")
- if not table_alias:
- return []
- return [c.name for c in table_alias.args.get("columns") or []]
-
- @property
def selects(self) -> t.List[Expression]:
return self.this.selects if isinstance(self.this, Subqueryable) else []
@@ -4860,8 +4860,18 @@ def maybe_parse(
return sqlglot.parse_one(sql, read=dialect, into=into, **opts)
+@t.overload
+def maybe_copy(instance: None, copy: bool = True) -> None:
+ ...
+
+
+@t.overload
def maybe_copy(instance: E, copy: bool = True) -> E:
- return instance.copy() if copy else instance
+ ...
+
+
+def maybe_copy(instance, copy=True):
+ return instance.copy() if copy and instance else instance
def _is_wrong_expression(expression, into):