On Apr 29, 2011, at 2:38 AM, monster jacker wrote:
> When i tested with 0.7b4 version of SQLAlchemy the above issue is
> resolved.Earlier i was testing with 0.6.6 version of SQLAlchemy.
> After doing the union_all when i try to do the
> query.order_by(desc('crt_dt')) on query object i am getting the programming
> error Invalid column name 'crt_dt'.since it is aliased, it is not getting the
> correct column name.
>
> def second_method(self):
> for tbl in Table: -----------------> for loop is
> used since we have 3 tables and doing union of them
> qry = some_method()
> query = query.union_all(qry) if query else qry
> if bundle:
> ----------------------------> if more than 1 table.
> query = query.order_by(desc('crt_dt'))
> return result_query.all()
>
> def some_method(self):
> query = self.session.query(Table.row_num.label('row_num'),
> Table.test_msg.label('test_msg'),
> Table.crt_dt.label('crt_dt'),
> Table2.name_file.label('name_file')).join(
> (Table2, Table2.some_idn == Table.some_idn))
> return query
>
>
> record = second_method()
SQLAlchemy's query construction does not interpret string arguments in terms of
what internal statement construct they may target, they are passed literally to
the rendered statement. In a case where a lot of nesting occurs, you can't
predict the string name of the column. Its always a good idea to use column
and expression objects across the board particularly when making use of the
automated unioning and aliasing services of Query. In this case it interprets
the originating column constructs as targeted to the outermost constructs so
the best choice here would be order_by(Table.crt_dt).
query.union() is not a widely used construct in the first place and is a little
awkward so I have some thoughts on some other ways at getting at those columns.
look for that in upcoming CHANGES and documentation.
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" 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/sqlalchemy?hl=en.