yeah use_labels probably needed.

or, you can also say:

select([table1.c.mycol.label('somelabel') , table1.c.othercolumn.label('otherlabel')])

to label columns.

in a related topic, if youre using use_labels, you can also address columns in the row based on the Column object directly:

        val = row[table.c.column3]

which searches for the column in the row by checking its name, its key, and its natural "label" (i.e. 'tablename_colname' usually, although theres some max-length logic that kicks in for long names)

On Apr 21, 2006, at 12:27 PM, Peter L. Buschman wrote:


I think I've answered my own question with the use_labels=True option to select(). ;-)

At 17:33 21.4.06, Peter L. Buschman wrote:

Most likely another newbie question, but how do I resolve an ambiguous column name that
is present in two tables after a joing?

For example, SQL lets me address the ambiguous column just by prefixing the table name.

SELECT table1.colum, table2.column
FROM table1
INNER JOIN table2 on table2.id = table1.id

However, if I perform the following query in SQL alchemy, I can only access by column name. Trying to access row['table1.column'] results in a KeyError exception.

query = select[table1, table2], from_obj=[
    table1.join(
        table2, table2.c.id == table1.c.id
    )
results = query.execute()
for row in results.fetchall():
        print row.column

How can I access both table1 and table2's column value from the same row object?




-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel? cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users






-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel? cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users



-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to