On Jul 29, 2013, at 8:43 PM, Gerald Thibault <dieselmach...@gmail.com> wrote:

> I have this simple class declaration:
> 
> class Item(Base):
>     __tablename__ = 'items'
>     id = Column(Integer, primary_key=True)
>     sub_id = Column(Integer, primary_key=True)
> 
> I'm trying to figure out how to get sqlalchemy to emit this sql:
> 
> SELECT * FROM items
> WHERE (id, sub_id) > (10,3)
> 
> but I'm unable to do it. I tried this:
> 
> query = session.query(Item) \
>         .filter((Item.id,Item.sub_id) > (10,3))
> 
> but the resulting sql completely omits the second column:
> 
> SELECT items.id AS items_id, items.sub_id AS items_sub_id 
> FROM items 
> WHERE items.id > ?
> 
> Does that second column/value actually get stored anywhere, or are they being 
> silently discarded?

well the mechanics of what's happening are probably an effect of how Python 
interprets the operator in conjunction with the tuple.  If you want SQLAlchemy 
to know about the tuple on the SQL side, use the tuple_ function:

from sqlalchemy import tuple_

q.filter(tuple_(item.id, item.sub_id) > tuple_(10, 3))

Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

Reply via email to