it was suggested by someone last week, for ordering dates that can be 
null, to use something like order_by( "start_date is not null, 
start_date, end_date is null, end_date"), i.e. use extra 
prefixing/suffixing boolean expressions to subcategorize the actual 
values.

so depending on where do u want those rows with (B!=0, C==0  ->inf) 
and (B==0, C==0 --> nan), u can put some extra expressoins in the 
order_by. 
or use CASE 

On Wednesday 25 June 2008 21:05:34 Michael Bayer wrote:
> 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 sqlalchemy@googlegroups.com
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