Cannot apply limit or offset when using ORM query.from_statement with not_ and exists

Issue #1304 resolved
Former user created an issue

Assume tables a and b which have ORM classes A and B mapped.

stmt = a.select().where( not_( exists( b ).where( a.c.id == b.c.a_id ) ) ).order_by( a.c.id ) a_list = session.query( A ).from_statement( stmt ).offset( 10 ).limit( 5 )

a_list contains all element specified by stmt, regardless of offset and limit. If offset and limit are applied to stmt, the work as expected. Take out the not_ and it works as expected (though it has a different meaning, of course).

Python 2.5.2, sqlalchemy 0.4.6, mysql 4.1.23

Comments (2)

  1. Former user Account Deleted

    For readability:

    stmt = a.select().where( not_( exists( b ).where( a.c.id == b.c.a_id ) ) ).order_by( a.c.id ) 
    a_list = session.query( A ).from_statement( stmt ).offset( 10 ).limit( 5 )
    
  2. Mike Bayer repo owner

    from_statement() does not support further modifications to the query since SQLA does not necessarily know anything about the structure of the given statement (straight text for example). Your use case raises in error in 0.5. You mean to be using select_from().

  3. Log in to comment