You seem to have stumbled into the same bug as I have while i fixed the 
"IN" SQL generation code for oracle to work inside the column list, not 
just in the where-clause.

I ended up hacking SQLAlchemy/trunk/lib/sqlalchemy/sql/expression.py 
like this:

2166 
<https://projects.freecode.no/internal/projects/browser/div4/div4c/software/SQLAlchemy/trunk/lib/sqlalchemy/sql/expression.py#L2166>
 
*class* _BinaryExpression(ColumnElement):
...
2181 
<https://projects.freecode.no/internal/projects/browser/div4/div4c/software/SQLAlchemy/trunk/lib/sqlalchemy/sql/expression.py#L2181>
 
    *def* *_get_from_objects*(self, **modifiers):
2182 
<https://projects.freecode.no/internal/projects/browser/div4/div4c/software/SQLAlchemy/trunk/lib/sqlalchemy/sql/expression.py#L2182>
 
        res = self.left._get_from_objects(**modifiers)
2183 
<https://projects.freecode.no/internal/projects/browser/div4/div4c/software/SQLAlchemy/trunk/lib/sqlalchemy/sql/expression.py#L2183>
 
        *if* self.operator *is* operators.in_op: *return* res
2184 
<https://projects.freecode.no/internal/projects/browser/div4/div4c/software/SQLAlchemy/trunk/lib/sqlalchemy/sql/expression.py#L2184>
 
        *return* res + self.right._get_from_objects(**modifiers)

That seems to do the trick :)

Best regards,
Egil


casbon wrote:
> Hi All,
>
> I am seeing something I didn't expect using in_.
>
> Here is a simple example, exactly as I expect:
>
>
> In [13]: col = Trade.c.TradeId.in_([1,2])
>
> In [14]: sel = select([col])
>
> In [15]: print col
> "Trade"."TradeId" IN (?, ?)
>
> In [16]: print sel
> SELECT "Trade"."TradeId" IN (?, ?) AS anon_1
> FROM "Trade"
>
>
> But now, if I use a subselect, I see a problem:
>
>
>
> In [17]: col = Trade.c.TradeId.in_(select([Trade.c.TradeId]))
>
> In [18]: sel = select([col])
>
> In [19]: print col
> "Trade"."TradeId" IN (SELECT "Trade"."TradeId"
> FROM "Trade")
>
> In [20]: print sel
> SELECT "Trade"."TradeId" IN (SELECT "Trade"."TradeId"
> FROM "Trade") AS anon_1
> FROM "Trade", (SELECT "Trade"."TradeId" AS "TradeId"
> FROM "Trade")
>
>
> The column definition (col) is as expected, but the select definition
> (sel) is strange.  It selects two things and generates n^2 rows.  How
> can I get the select I expect:
>
> SELECT "Trade"."TradeId" IN (SELECT "Trade"."TradeId"
> FROM "Trade") AS anon_1
> FROM "Trade"
>
> thanks,
> James
>
> --~--~---------~--~----~------------~-------~--~----~
> 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
> -~----------~----~----~----~------~----~------~--~---
>
>   

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to