try this trick: db.Table1.blah = db.Table1.bar.clone(name = 'blah', _rname='bar') db(...).select(db.Table1.blah)
On Tuesday, August 29, 2017 at 3:11:36 AM UTC+3, Paolo Caruccio wrote: > > Maybe > > def test(): > rows = db(db.Table1.foo==db.Table2.foo).select(db.Table1.foo. > with_alias('foo'), db.Table2.bar.with_alias('blah')) > for row in rows: > print row.foo, row.blah > return locals() > > should work. > > Another way - if you can rewrite tables definitions - is to use the > "rname" field value. From the web2py book > http://www.web2py.com/books/default/chapter/29/06/the-database-abstraction-layer?#Field-constructor > > >> >> *rname* provides the field was a "real name", a name for the field known >> to the database adapter; when the field is used, it is the rname value >> which is sent to the database. *The web2py name for the field is then >> effectively an alias*. > > > So with > > db.define_table('Table2', Field('blah', 'string', rname="bar") > > the query becomes > > db(db.Table1.foo==db.Table2.foo).select(db.Table1.foo, db.Table2.blah) > > If you want alias fields in a query without joins you could write > > rows = db(db.Table2.id>0).select('bar AS blah') > > > > Il giorno lunedì 28 agosto 2017 08:50:20 UTC+2, Brendan Barnwell ha > scritto: >> >> On Monday, July 31, 2017 at 1:25:31 PM UTC-7, Paolo Caruccio wrote: >>> >>> Maybe the web2py book could help you: >>> >>> >>> http://www.web2py.com/books/default/chapter/29/06/the-database-abstraction-layer?search=with_alias#Self-Reference-and-aliases >>> >>> >> That appears to only be talking about using aliases for tables, and >> specifically to be able to create and query tables that reference one >> another. What I'm describing is conceptually much simpler than that: I >> just want to take a query that already works and give my own names to the >> columns of the result. >> > -- 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. For more options, visit https://groups.google.com/d/optout.