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.
>>>
>>

-- 



Reply via email to