[web2py] Re: Unions and select from tables

2012-07-22 Thread Massimo Di Pierro
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 ... > > I

[web2py] Re: Unions and select from tables

2012-07-21 Thread Cliff Kachinske
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: > > Yo

[web2py] Re: Unions and select from tables

2012-07-21 Thread Massimo Di Pierro
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 differ

[web2py] Re: Unions and select from tables

2012-07-21 Thread Cliff Kachinske
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

[web2py] Re: Unions and select from tables

2012-07-20 Thread Massimo Di Pierro
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().sele

[web2py] Re: Unions and select from tables

2012-07-20 Thread Cliff Kachinske
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

[web2py] Re: Unions and select from tables

2012-07-20 Thread Andrew
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 (pictu

[web2py] Re: Unions and select from tables

2012-07-20 Thread Massimo Di Pierro
I see what you are doing and I like it. I think it may be tricky to implement but I look forward to see what you come up to. I think: *db( (db.sample.id>0) and (db.example.id>0) and (db.random.id>0)).select()* * * should be * * *db( (db.sample.id>0) & (db.example.id>0) & (db.random.id>0)).select(