On Jun 22, 2007, at 9:59 AM, Christoph Haas wrote:

>
> Dear list,
>
> I'm trying to join a table with itself. That works well. However since
> the column names are identical I had no luck accessing both the  
> original
> and the joined information.
>
> I have aliased the tables already and run the join on the aliased  
> names.
> But the column names are still not qualified.
>
> Example:
>
> records_a   = model.records_table.alias('records_a')
> records_ptr = model.records_table.alias('records_ptr')
> joined = records_a.select(...,
>     from_obj=[outerjoin(records_a, records_ptr,
>     records_a.c.foo==records_ptr.c.bar)).execute().fetchone()
>
> The records contain fields like 'id', 'type' or 'name'. So I tried
> this and failed:
>
> print joined[0].records_a.c.id
> print joined[0]['records_a.id']
>

that makes no sense.  joined is a result of fetchone() so it  
therefore a RowProxy.  joined[0] is the first column of the row.  the  
value of joined[0] should be a scalar.

to see all the literal column names, use result.fetchone().keys().   
or, just turn on SQL echoing and watch the names generated.  the  
easiest way to get at the column you want is to target using the  
Column objects themselves:

result.fetchone()[records_a.c.id]



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to