diff --git a/querybuilder/atoms/columns.py b/querybuilder/atoms/columns.py index fd845a20fae99a18c43dc20cc2adbe261f4fe623..301d14d2cfff877217153c1c46856ede3bfada66 100644 --- a/querybuilder/atoms/columns.py +++ b/querybuilder/atoms/columns.py @@ -140,6 +140,11 @@ class Column(Atom): """ return Not(self) + @columnize + @method_accepting_lambdas + def coalesce(self, *others, **kwargs): + return Coalesce(self.pretuple_with(*others), **kwargs) + def compress(self, *, unsafe=False): """Method to compress a column into an equivalent one @@ -923,8 +928,8 @@ class Pretuple(Expression, Generic[Col]): sqltype = tuple((c.sqltype for c in columns)) super().__init__(columns=columns, sqltype=sqltype, **kwargs) - def coalesce(self, **kwargs): - return Coalesce(self, **kwargs) + def coalesce(self, *others, **kwargs): + return self.columns[0].__class__.coalesce(*self.columns, *others, **kwargs) def to_placeholder(self, key: Optional[str | _MISSING_TYPE] = None) -> Placeholder: raise NotImplementedError() @@ -967,6 +972,7 @@ class Pretuple(Expression, Generic[Col]): @columnize @method_accepting_lambdas def pretuple_with(self, *others): + # TODO: Why not done as follows in Column class? if not others: return self