[sqlalchemy] Re: Problem with subquery

2007-08-10 Thread Michael Bayer
On Aug 10, 1:56 pm, "Mike Orr" <[EMAIL PROTECTED]> wrote: > Er, where is it you're not supposed to use .c? The code in MikeB's > example seems to have .c in every possible location. How do you > access a column without .c? ive clarified this in 0.4's behavior. lets take a query like this:

[sqlalchemy] Re: Problem with subquery

2007-08-10 Thread Mike Orr
Er, where is it you're not supposed to use .c? The code in MikeB's example seems to have .c in every possible location. How do you access a column without .c? On 8/10/07, Jeronimo <[EMAIL PROTECTED]> wrote: > > Excelent ! It works perfectly !! > Thank you very much Michael. I was going crazy tr

[sqlalchemy] Re: Problem with subquery

2007-08-10 Thread Jeronimo
Excelent ! It works perfectly !! Thank you very much Michael. I was going crazy trying to figure how to move subquery to the from clause. On Aug 9, 8:06 pm, Michael Bayer <[EMAIL PROTECTED]> wrote: > OK sorry, i didn't look carefully enough. when you use a scalar > subquery, you shouldn't acce

[sqlalchemy] Re: Problem with subquery

2007-08-09 Thread Michael Bayer
OK sorry, i didn't look carefully enough. when you use a scalar subquery, you shouldn't access the "c" attribute on it. I hadn't really realized that and maybe i should add an exception for that. when you access the "c" attribute, you're treating it like another relation to be selected from, so

[sqlalchemy] Re: Problem with subquery

2007-08-09 Thread Jeronimo
I cant manage to make sub_select appear at WHERE level, it always appears at FROM level. The SQL statement needs to select one node for each type, and each node must be the one with the max id in that type. Is it possible to make this statement using SQLAlchemy ? On Aug 9, 6:11 pm, Jeronimo <[

[sqlalchemy] Re: Problem with subquery

2007-08-09 Thread Jeronimo
I'm using version 0.3.9 with PostgresSQL 8.1 . Because postgres needs aliased subqueries i changed the example code you sent to: n1 = node_table.alias('n1') sub_query = select([func.max(node_table.c.id).label('max_id')], (node_table.c.type_id==n1.c.type_id), scalar=True) sub_query.correlate(n1) s

[sqlalchemy] Re: Problem with subquery

2007-08-09 Thread Michael Bayer
if youre on 0.3, you can explicitly correlate to n1 by saying: myselect.correlate(n1) also in 0.3, it would probably help to say "scalar=True" in your select() statement (and you dont need the alias): n1 = node_table.alias('n1') sub_query = select([func.max(node_table.c.id).label('max_id')],