you should use this to get at the column:
col = s1.corresponding_column(col)
of course trac is down so nothing is happening too soon at the moment.
On Jul 21, 2006, at 4:15 PM, Randall Smith wrote:
> Attached is a proposed patch.
>
> Randall
>
> Randall Smith wrote:
>> How about this:
>> def min(self, col):
>> """executes the SQL min() function against the given
>> column"""
>> s1 = sql.select([col], self._clause, **self._ops).alias('u')
>> s2 = sql.select([sql.func.min(getattr
>> (s1.c,col.name))]).scalar()
>> return s2
>> Randall
> Index: selectresults.py
> ===================================================================
> --- selectresults.py (revision 1729)
> +++ selectresults.py (working copy)
> @@ -29,22 +29,28 @@
> def count(self):
> """executes the SQL count() function against the
> SelectResults criterion."""
> return self._query.count(self._clause)
> +
> + def _col_aggregate(self, col, func):
> + """executes func() function against the given column"""
> + s1 = sql.select([col], self._clause, **self._ops).alias('u')
> + result = sql.select([func(getattr(s1.c, col.name))]).scalar()
> + return result
>
> def min(self, col):
> """executes the SQL min() function against the given
> column"""
> - return sql.select([sql.func.min(col)], self._clause,
> **self._ops).scalar()
> + return self._col_aggregate(col, sql.func.min)
>
> def max(self, col):
> """executes the SQL max() function against the given
> column"""
> - return sql.select([sql.func.max(col)], self._clause,
> **self._ops).scalar()
> + return self._col_aggregate(col, sql.func.max)
>
> def sum(self, col):
> """executes the SQL sum() function against the given
> column"""
> - return sql.select([sql.func.sum(col)], self._clause,
> **self._ops).scalar()
> + return self._col_aggregate(col, sql.func.sum)
>
> def avg(self, col):
> """executes the SQL avg() function against the given
> column"""
> - return sql.select([sql.func.avg(col)], self._clause,
> **self._ops).scalar()
> + return self._col_aggregate(col, sql.func.avg)
>
> def clone(self):
> """creates a copy of this SelectResults."""
> ----------------------------------------------------------------------
> ---
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to
> share your
> opinions on IT & business topics through brief surveys -- and earn
> cash
> http://www.techsay.com/default.php?
> page=join.php&p=sourceforge&CID=DEVDEV________________________________
> _______________
> Sqlalchemy-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Sqlalchemy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users