In SQLite, the tilde (~) is a unary operator used for bitwise negation. If used as a prefix for an order by column, SQLite will not throw an error (as it is a valid operator), but nor will sort they way you expect. In Postgres, the tilde is not a unary operator but a regular expression operator, so when used in this way, it will throw an error. In any case, in SQL, "DESC" is used to indicate descending order ("ASC" for ascending).
So, you can do: orderby='shares DESC' Anthony On Monday, June 17, 2019 at 11:48:51 PM UTC-4, Vlad wrote: > > This works perfect in SQLite: > > rows = db(query).select(db.cart_sharing.created_by.with_alias('sharer' > ), > db.cart_sharing.stats.count().with_alias( > 'carts'), > db.cart_sharing.stats.sum().with_alias('shares' > ), > groupby=db.cart_sharing.created_by, > orderby=['~shares']) > > > 'shares' is alias to sum(), and sqlite understands exactly what's needed - > sorts by the number of shares. > > Posgres doesn't like it: > <class 'psycopg2.ProgrammingError'> column "shares" does not exist > LINE 1: ...NULL) GROUP BY "cart_sharing"."created_by" ORDER BY ~shares; ^ > > What's the proper DAL syntax for such a thing compatible with Postgres? > > > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/1defc9ec-6991-4170-96d4-997b5d03c60e%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.