diff --git a/pypika/terms.py b/pypika/terms.py index c522550a..1c804e2e 100644 --- a/pypika/terms.py +++ b/pypika/terms.py @@ -619,9 +619,11 @@ def nodes_(self) -> Iterator[NodeT]: for value in self.values: yield from value.nodes_() - def get_sql(self, **kwargs: Any) -> str: + def get_sql(self, with_alias: bool = False, **kwargs: Any) -> str: sql = "({})".format(",".join(term.get_sql(**kwargs) for term in self.values)) - return format_alias_sql(sql, self.alias, **kwargs) + if with_alias: + return format_alias_sql(sql, self.alias, **kwargs) + return sql @property def is_aggregate(self) -> bool: @@ -812,13 +814,15 @@ def replace_table(self, current_table: Optional["Table"], new_table: Optional["T """ self.term = self.term.replace_table(current_table, new_table) - def get_sql(self, subquery: Any = None, **kwargs: Any) -> str: + def get_sql(self, subquery: Any = None, with_alias: bool = False, **kwargs: Any) -> str: sql = "{term} {not_}IN {container}".format( term=self.term.get_sql(**kwargs), container=self.container.get_sql(subquery=True, **kwargs), not_="NOT " if self._is_negated else "", ) - return format_alias_sql(sql, self.alias, **kwargs) + if with_alias: + return format_alias_sql(sql, self.alias, **kwargs) + return sql @builder def negate(self) -> "ContainsCriterion": @@ -920,12 +924,14 @@ def replace_table(self, current_table: Optional["Table"], new_table: Optional["T """ self.term = self.term.replace_table(current_table, new_table) - def get_sql(self, **kwargs: Any) -> str: + def get_sql(self, with_alias: bool = False, **kwargs: Any) -> str: sql = "({term} & {value})".format( term=self.term.get_sql(**kwargs), value=self.value, ) - return format_alias_sql(sql, self.alias, **kwargs) + if with_alias: + return format_alias_sql(sql, self.alias, **kwargs) + return sql class NullCriterion(Criterion): @@ -955,7 +961,9 @@ def get_sql(self, with_alias: bool = False, **kwargs: Any) -> str: sql = "{term} IS NULL".format( term=self.term.get_sql(**kwargs), ) - return format_alias_sql(sql, self.alias, **kwargs) + if with_alias: + return format_alias_sql(sql, self.alias, **kwargs) + return sql class NotNullCriterion(NullCriterion): @@ -1180,10 +1188,12 @@ def nodes_(self) -> Iterator[NodeT]: yield self yield from self.term.nodes_() - def get_sql(self, **kwargs: Any) -> str: + def get_sql(self, with_alias: bool = False, **kwargs: Any) -> str: kwargs["subcriterion"] = True sql = "NOT {term}".format(term=self.term.get_sql(**kwargs)) - return format_alias_sql(sql, self.alias, **kwargs) + if with_alias: + return format_alias_sql(sql, self.alias, **kwargs) + return sql @ignore_copy def __getattr__(self, name: str) -> Any: @@ -1228,9 +1238,11 @@ def nodes_(self) -> Iterator[NodeT]: yield self yield from self.term.nodes_() - def get_sql(self, **kwargs: Any) -> str: + def get_sql(self, with_alias: bool = False, **kwargs: Any) -> str: sql = "{term} ALL".format(term=self.term.get_sql(**kwargs)) - return format_alias_sql(sql, self.alias, **kwargs) + if with_alias: + return format_alias_sql(sql, self.alias, **kwargs) + return sql class CustomFunction: @@ -1317,8 +1329,7 @@ def get_function_sql(self, **kwargs: Any) -> str: special=(" " + special_params_sql) if special_params_sql else "", ) - def get_sql(self, **kwargs: Any) -> str: - with_alias = kwargs.pop("with_alias", False) + def get_sql(self, with_alias: bool = False, **kwargs: Any) -> str: with_namespace = kwargs.pop("with_namespace", False) quote_char = kwargs.pop("quote_char", None) dialect = kwargs.pop("dialect", None)