Not without some hacks I would not suggest. On Saturday, 21 July 2012 23:15:26 UTC-5, Cliff Kachinske wrote: > > I didn't ask the question correctly. > > In raw sql it would be something like > > SELECT name FROM table, CONCAT (first_name, last_name) FROM othertable AS > name WHERE blah ... > > Is it possible to do that without using raw sql? > > On Saturday, July 21, 2012 9:54:09 PM UTC-4, Massimo Di Pierro wrote: >> >> You do not have to. The line: >> >> y.colnames=x.colnames >> >> does it for you, as long as the list of fields maps 1 to 1. >> >> On Saturday, 21 July 2012 20:10:09 UTC-5, Cliff Kachinske wrote: >>> >>> This is great. >>> >>> I've not tried it yet, but I'm assuming I can alias the field names if >>> the tables have different field names with the same data type. >>> >>> Is it possible to combine two field names into a single alias? >>> >>> Thanks >>> >>> On Friday, July 20, 2012 5:35:37 PM UTC-4, Massimo Di Pierro wrote: >>>> >>>> You can also to >>>> >>>> db=DAL()db.define_table('a',Field('name')) >>>> db.define_table('b',Field('name')) >>>> db.a.insert(name='Alex') >>>> db.a.insert(name='Max') >>>> db.a.insert(name='Tim') >>>> db.b.insert(name='John') >>>> db.b.insert(name='Jack') >>>> def union(x,y): >>>> y.colnames=x.colnames >>>> return x|y >>>> >>>> *rows = union(db().select(db.a.name),db().select(db.b.name)).sort(lambda >>>> row: row.name)* >>>> >>>> for row in rows: print row.name >>>> >>>> >>>> This does not translate into a union and runs at the web2py level. Mind >>>> that while testing I notice a discrepancy between docs and implementation >>>> of the sort() method. I fixed it in trunk. This code will only work with >>>> trunk. >>>> >>>> Massimo >>>> >>>> >>>> On Friday, 20 July 2012 16:08:16 UTC-5, Cliff Kachinske wrote: >>>>> >>>>> You can avoid a union like so: >>>>> >>>>> rows = db(q).select(r).as_list() >>>>> rows.extend(db(qq).select(rr).as_list() >>>>> >>>>> >>>>> >>>>> You have to access attributes dictionary fashion, not in dot notation. >>>>> Could be a problem for SQLTABLE and descendants. >>>>> >>>>> Google 'sort list of dictionaries' to see how to sort it. >>>>> >>>>> On Friday, July 20, 2012 3:00:58 PM UTC-4, Andrew wrote: >>>>>> >>>>>> Does that mean sample, example, random have to have identical >>>>>> structures ? >>>>>> What if I just want the id and name columns ? How do I select just >>>>>> those in a union scenario? >>>>>> >>>>>> I know massimo doesn't like unions, but they are required sometimes. >>>>>> I am visualizing object relationships in a graph (picture something >>>>>> like >>>>>> http://bost.ocks.org/mike/fisheye ) and I want to get one list of >>>>>> nodes. I've only done it with executesql so far. >>>>>> >>>>>
--