Thanks, I think that's exactly what I was looking for!


.oO V Oo.


On 12/28/2011 06:10 PM, Michael Bayer wrote:
On Dec 27, 2011, at 8:37 PM, Vlad K. wrote:

Hi all.


I need to select some rows where pkey is in a sequence. How do I order by that 
very sequence?


images_all = 
session.query(AdImage).filter(AdImage.image_id.in_(images)).order_by(  ?  
).all()


Postgresql backend.
typically with case():

order_by(
     case([
           (Adimage.id == 3, "A"),
           (Adimage.id == 1, "B"),
           (Adimage.id == 9, "C"),
     ])
)

unless you can use a simpler transformation on AdImage.id that converts it into 
a sortable value.

The above can be generalized:

case([(AdImage.id == value, literal(index)) for index, value in 
enumerate(images)])




--
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to