On Jul 27, 2011, at 5:30 PM, Christoph Zwerschke wrote: > Most databases allow ordinal numbers as expressions in order by clauses, some > even in group by clauses. And in earlier versions of SQLAlchemy it had in > fact been possible to express these as integers, e.g. query.order_by(1, 3, > desc(2)). > > However, in version 0.7.1 this yields an "SQL expression object or string > expected" error. To make use of this feature you now need to write > query.order_by('1', '3', desc('2')) which is not so readable and convenient > as the above. Has this been changed by intent?
Well of course its going through the literal_as_text() function which ensures what's given can be rendered as SQL. The function was sloppier in 0.6 and we had user confusion when clearly non-complaint objects were passed through to various places (such as and_(("a", ), ("b",)), etc.). order_by() is accepting SQL expressions, not values, so it is consistent that values should be coerced to SQL first in this case literal_column("1"), etc. If you want uber-readable, I'd do this: def ordinal(n): return literal_column(str(n)) ordinal(1), ordinal(2).desc(), etc. I'm not actually understanding what "ORDER BY 1" is getting you here in any case or how this relates to AJAX. > I know, using ordinals has some drawbacks and may be considered a bad habit, > but they can still be useful in some situations. E.g. it makes it possible to > decorate arbitrary queries of the same structure for use in an autosuggest > AJAX controller with an "order_by(1)". > > -- Christoph > > -- > 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. > -- 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.