oh sorry, there is a new flag that I have not documented yet called "correlated", you need to set that to false (although it shouldnt be needed for this example, thats slightly buggy):

subq = users.select(order_by=[users.c.username], limit=2, correlate=False).alias('users')

s = select(
        [subq.c.username, roles.c.role],
        from_obj = [
                subq.join(roles, subq.c.username==roles.c.username)
        ]
)


the query I get is:

SELECT users.username, roles.role
FROM (SELECT users.username AS username
FROM users ORDER BY users.username
LIMIT 2) AS users JOIN roles ON users.username = roles.username

On Mar 17, 2006, at 1:54 AM, sifu wrote:

hi!

On 3/16/06, Michael Bayer <[EMAIL PROTECTED]> wrote:
I need to document the "from_obj" parameter better:

subq = users.select(order_by=[users.c.username], limit=2).alias ('users')

select(
        [subq.c.username, roles.c.role],
        from_obj = [
                subq.join(roles, subq.c.username==roles.c.username)
        ]
)

i tried this already once before, but postgres isn't happy with the
resulting query:
SQLError: (ProgrammingError) missing FROM-clause entry in subquery for
table "users"

here is the query sqlalchemy generates:
SELECT users.username, roles.role
FROM (SELECT users.username AS username, users.password AS password,
users.email AS email ORDER BY users.username
 LIMIT 2) AS users JOIN roles ON users.username = roles.username

thank you,
sifu


On Mar 16, 2006, at 4:43 AM, sifu wrote:

hi!

i'm not able to come up with a way to express the following postgresql
query with sqlalchemy:

SELECT users.username, roles.role
FROM ( SELECT * FROM users ORDER BY username LIMIT 2 ) AS users
LEFT JOIN roles ON users.username = roles.username;

i hope someone can help me out here :)

what i want to achieve (and what the postgresql query does):
i have to tables one with users one with all the roles of an user.
and i want to get 2 users but with all the roles they have.

thanks in advance!
sifu
ps: sqlalchemy is awesome! the only limiting factor seems to be my
stupidity :)


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting
language
that extends applications into web and mobile media. Attend the
live webcast
and join the prime developer group breaking into this new coding
territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users





-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to