I have three tables, db.table1 db.table2 and db.table3. They are identical 
except for the information stored in each. table3 is blank and after 
running some code should contain the combination of the values in table1 
and table2. 

An example (<uuid> is generated by web2py_uuid()):

db.table1:
col1 col2 col3 col4 col5 col6 col7 col8
1    A    Z    x    x              <uuid>
2    B    Y    x    x              <uuid>
3    C    X    x    x              <uuid>
4    D    W    x    x              <uuid>

db.table2:
col1 col2 col3 col4 col5 col6 col7 col8
1    A    Z              y    y    <uuid>
2    B    Y              y    y    <uuid>
3    C    X              y    y    <uuid>
4    D    W              y    y    <uuid>

After merging, db.table3 should look like this:

db.table3:
col1 col2 col3 col4 col5 col6 col7 col8
1    A    Z    x    x    y    y    <uuid>
2    B    Y    x    x    y    y    <uuid>
3    C    X    x    x    y    y    <uuid>
4    D    W    x    x    y    y    <uuid>

After some research, I found that exporting table1 and table2 to separate 
.csv files and then importing them into table3 should be an easy way to do 
this, however it does not seem to be working for me. Below is the code I've 
tried to use:

rows = db(db.table1).select()
rows.export_to_csv_file(open('table1.csv','wb'))
db.table3.import_from_csv_file(open('table1.csv','rb'),unique='col1')
    
rows = db(db.table2).select()
rows.export_to_csv_file(open('table2.csv','wb'))
db.table3.import_from_csv_file(open('table2.csv','rb'),unique='col1')

The problem I'm having is only the values from table2 are showing in table3.

I've also tried using a join like this:

db(db.table1.col1 == db.table2.col1).select()

But it creates something which looks like this:

col1 col2 col3 col4 col5 col6 col7 col8   col1 col2 col3 col4 col5 col6 
col7 col8
1    A    Z    x    x              <uuid> 1    A    Z              y    
y    <uuid>
2    B    Y    x    x              <uuid> 2    B    Y              y    
y    <uuid>
3    C    X    x    x              <uuid> 3    C    X              y    
y    <uuid>
4    D    W    x    x              <uuid> 4    D    W              y    
y    <uuid>

Is there another way of doing the join which would produce table3 how I'd 
like it formatted?

Anyone have a suggestion or better way to do this?

Thanks,
David

-- 

--- 
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/groups/opt_out.


Reply via email to