that's an intricate trick which currently doesn't work with the ORM. #1852 is
added to see if there's a quick way to fix this (very likely there isn't
something quick).
You'd have to trick it using column("email") or something like that.
On Jul 13, 2010, at 3:02 PM, Andrew Bialecki wrote:
> I tried to write the following code assuming a User class with
> first_name, last_name, and email:
>
> search_term = "Andrew"
>
> by_email = session.query(User.email.label("text"),
> User.email.label("email")).filter(User.email.like("%%%s%%" %
> search_term)
> by_first_name = session.query(User.first_name.label("text"),
> User.email.label("email")).filter(User.first_name.like("%%%s%%" %
> search_term)
> matches = by_email.union_all(by_first_name).all()
>
> with the hope that this would return rows like so:
>
> text email
> ----- -------
> [email protected] [email protected]
> Andrew [email protected]
>
> However, I get:
>
> text email
> ----- -------
> [email protected] [email protected]
> Andrew Andrew
>
> When I look at the SQL, the wrapper select for the UNION is wrong.
> Any idea how to get the behavior I want? Thanks!
>
> --
> 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.
>
--
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.