def get_sql(self, with_alias: bool = False, **kwargs: Any) -> str: if not self._cases: raise CaseException( "At least one 'when' case is required for a CASE statement." ) cases = " ".join( "WHEN {when} THEN {then}".format( when=criterion.get_sql(**kwargs), then=term.get_sql(**kwargs) ) for criterion, term in self._cases ) else_ = " ELSE {}".format(self._else.get_sql(**kwargs)) if self._else else "" case_sql = "CASE {cases}{else_} END".format(cases=cases, else_=else_) if with_alias: return format_alias_sql(case_sql, self.alias, **kwargs) return case_sql
def get_sql(self, with_alias=False, with_namespace=False, quote_char=None, dialect=None, **kwargs): args = [] for p in self.args: if hasattr(p, "get_sql"): args.append('toString("{arg}")'.format( arg=p.get_sql(with_alias=False, **kwargs))) else: args.append(str(p)) sql = "{name}({args},[{patterns}])".format( name=self.name, args=",".join(args), patterns=",".join(["'%s'" % i for i in self._patterns]), ) return format_alias_sql(sql, self.alias, **kwargs)