On Jun 25, 12:36 pm, Dominique <[EMAIL PROTECTED]> wrote:
> Hello,
>
> A beginner question:
> I have a table with 4 columns: id, colA, colB, colC.
> I want to order (and make other operations as well ) the table asc or
> desc using the result of colB / colC knowing that colB and colC may
> equal to 0.
>
> When I try using query, the returned results are not correctly
> ordered:
> session.query(Mytable).order_by(asc(Mytable.colB /
> Mytable.colC)).all()
> I guess that the zero present in colB and colC may also interfere
>
> Is it possible to do this with queries with SA 0.4.6 ?
> Should I use select() and how or is it preferable to go for SA 0.5 ?

it should be fine from a SQL generation perspective either way.  To
confirm this turn on SQL echoing, most easily by passing "echo=True"
to your create_engine() call.   As far as the ordering actually
working, I'm not sure about typical database behavior when a division
can result in a divide by zero - it would either raise an error or
produce a NaN value (I think the latter might be more common).  As far
as how that orders you'd have to read the documentation for the DB in
use.  To have explicit cases set up for the divisor, use a CASE
expression (which SQLA will generate for you using the case()
construct).

>
> How should I do to get what I want ?
>
> Additional question:
> I ordered Essential SqlAlchemy on the French Amazon, but haven't
> received it yet (may be still on print ?).
> Does anybody know if it has been issued already in the US  ?
>
> Many thanks in advance for helping me
>
> Dominique
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to