Excerpts from Bryan's message of Tue Mar 30 11:27:57 -0300 2010:
> The underlying column returns a Decimal object when queried regularly,
> and when summed as follows:
> 
> select([ mytable.c.hours ])
> >>>Decimal("1.0")
> select([ func.sum(mytable.c.hours) ])
> >>>Decimal("1.0")
> 
> ...but when I sum it w/ an if statement, it returns a float:
> 
> select([ func.sum(func.if_(True, mytable.c.hours, 0)) ])
> >>>1.0
> 
> How can I control the return type of that summed if column?
> 

You could use cast [1] (example: casting to Float, untested):

from sqlalchemy.sql.expression import cast
from sqlalchemy.sa import Float
...
select([ cast(func.sum(func.if_(True, mytable.c.hours, 0)), Float)])

[1] 
http://www.sqlalchemy.org/docs/reference/sqlalchemy/expressions.html#sqlalchemy.sql.expression.cast

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to