On Jul 20, 2010, at 8:24 PM, Mariano Mara wrote:
> Hi there,
> I have these two tables (with very long column names and most of them
> with the same names in both tables) I want to join. Since I will be
> processing the results afterwards, I would like to have shorten names
> to type less and clearly differentiated names to avoid conflicts.
> So I pass the use_labels param to the select statement and apply
> labels to both tables.
> E.g.:
> select([service.alias('a'), history.alias('b')], use_labels=True)
> which generates the following sql:
> select a.id as a_id, a.valid_flag as a_valid_flag, a.code as
> a_code, ...more columns with 'a' alias, b.id as b_id, ... more column
> with 'b' alias from service as a, history as b...
>
> The problem is when I add a where clause (or I think it's the
> problem):
> select([service.alias('a'), history.alias('b')],
> and_(service.c.id==history.c.id, service.c.valid_flag==True),
> use_labels=True)
once you make an alias(), that's your selectable. Using "service" refers to
the original table. You want to be using the alias() object of "service" in
your and_().
--
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.