On Jun 27, 11:05 am, klaus <[EMAIL PROTECTED]> wrote:

> table = join(table1, table2, table1.c.id ==
> table2.c.fk).select(table2.c.id == 42).alias("s")

>
> # This prints ['id', 'fk']. Shouldn't there be three columns? And
> where is the prefix "s"?
>

joins have a different behavior than select(), in that a join
"assumes" column name collisions are likely and therefore applies the
table name as a prefix to its exported columns in all cases.  since a
join() isnt really a full blown "select" object its actually not so
common that people call upon its exported col list.  the select() otoh
doesnt assume you want to prefix column names with the table name, the
use_labels flag must be added.  without it, your column list is
shorter due to name collisions.

table = join(table1, table2, table1.c.id ==
table2.c.fk).select(table2.c.id == 42, use_labels=True).alias("s")

print table.c.keys()

['table1_id', 'table2_id', 'table2_fk']

the "s" is part of the alias, external to the select.  to have that
show up, select from the alias:

table = join(table1, table2, table1.c.id ==
table2.c.fk).select(table2.c.id == 42,
use_labels=True).alias("s").select(use_labels=True)

print table.c.keys()

['s_table1_id', 's_table2_id', 's_table2_fk']



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
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