On Jun 9, 2008, at 11:34 AM, Christoph Zwerschke wrote:

>
> I need to order a table by start and end dates, where null values  
> should
> be interpreted as "prior to all values" for start dates and "later  
> than
> all values" for end dates.
>
> This could be realized with "nulls first", "nulls last", but it seems
> this did not make it into SQLAlchemy yet (ticket #723).
>
> A workaround (for PostgreSQL) would be something like this:
>
> order_by coalesce(start, timestamp '-infinity'),
>       coalesce(end_date, timestamp 'infinity')
>
> But I don't find how to construct this with SQLAlchemy. Any ideas? Any
> better solutions?


I tend to use a CASE statement for this:  CASE WHEN x IS NULL THEN 0  
ELSE x .   We have case() construct for that.

For your version, use func.coalesce(start, literal_column("timestamp '- 
infinity'")) .



--~--~---------~--~----~------------~-------~--~----~
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