Transplanting _order_by_clause when wrapping into subquery

8 views
Skip to first unread message

Gunnlaugur Briem

unread,
May 31, 2012, 8:34:36 AM5/31/12
to sqlal...@googlegroups.com
Hi,

When wrapping a query with an enclosing query to add columns computed from the original query's columns, I'm blatantly doing this:

        order_clause_list = ClauseList(*fact_query._order_by_clause)
        fact_query._order_by_clause = ClauseList()
        subq = fact_query.alias('forperc')
        return select(
            [subq.c[k] for k in subq.c.keys()] + [
                <extra columns based on subq's columns>
                for dim in percentage_dims
                ]
            ).order_by(*order_clause_list)

since I want the original query's ordering, and subquery ordering is not guaranteed to be maintained.

This works (in 0.7.5). But it messes with internals (_order_by_clause). So is there a more proper way to do this (for general queries), against the public sql.expression API?

Regards,

Gulli
Reply all
Reply to author
Forward
0 new messages