On May 18, 2011, at 12:33 AM, Yap Sok Ann wrote: > > author_name = column_property( > select( > [Author.name], > author_id == Author.id, > ).label('author_name') > ) > > > Base.metadata.create_all(engine) > > Session.query(Book).order_by('id').all() > Session.query(Book).order_by('id').limit(5).offset(5).all() > ################################################# > > the 2nd query will fail with this error: > > sqlalchemy.exc.ProgrammingError: (ProgrammingError) ('42S22', "[42S22] > [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid column name > 'name'. (207) (SQLExecDirectW); [42000] [Microsoft][ODBC SQL Server > Driver][SQL Server]Statement(s) could not be prepared. (8180)") > u'SELECT anon_1.name, anon_1.books_id, anon_1.books_title, > anon_1.books_author_id \nFROM (SELECT (SELECT authors.first_name + ? > +authors.last_name AS name \nFROM authors \nWHERE books.author_id = > authors.id) AS author_name, books.id AS books_id, books.title AS > books_title, books.author_id AS books_author_id, ROW_NUMBER() OVER > (ORDER BY id) AS mssql_rn \nFROM books) AS anon_1 \nWHERE mssql_rn > ? > AND mssql_rn <= ?' (' ', 5, 10) > > Somehow it selects anon_1.name instead of anon_1.contact_name. I got > the error on both 0.6.7 and 0.7b4.
now that is interesting, and its a bug, and why its unusual is because you've got a column_property() deriving from another column_property(). But the bug is interestingly a very simple one inside the select() construct. I still have to figure out how to fix it. Here's a workaround for the moment: author_name = column_property( select( [Author.name.__clause_element__().element], author_id == Author.id, ).label('author_name') ) -- 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.