Tomasz Narloch pisze:
> I have problem with creating object relation query
>
> I want to receive below query from sqlAlchemy:
>
> SELECT * FROM price WHERE price_category_id BETWEEN 1 AND 5 AND
> (beginner=1 OR (beginner=0 AND price_category_id NOT IN (SELECT
> price_category_id FROM price WHERE price_category_id BETWEEN 1 AND 5 AND
> beginner=1 ORDER BY id)))
>
> desc: all rows with beginner == 1 and rows with beginner == 0 if rows
> with that price_category_id doesn't have beginner == 1
>
> I start with:
>
> Session.query(Price.id, Price.price_category_id).\
> filter(and_(Price.price_category_id <= 5,
> Price.price_category_id >=1)).\
> filter( or_(Price.beginner == 1,
> and_(Price.beginner == 0, Price.price_category_id
> ...!!!)
> )
> ).all()
>
>
I have resolved this:)
subquery = select([Price.price_category_id], and_(Price.beginner == 1,
Price.price_category_id.between(1,5)))
Session.query(Price.id,
Price.price_category_id).filter(and_(Price.price_category_id.between(1,5),\
or_(Price.beginner == 1,and_(Price.beginner ==
0, not_(Price.price_category_id.in_(subquery)))))).all()
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pylons-discuss" 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/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---