from sqlalchemy import not_
session.query(Region).filter(not_(Region.id.in_( (1,2,3) )))

alternately,
session.query(Region).filter(~ Region.id.in_( (1,2,3) ))


On Tue, Sep 2, 2008 at 6:59 AM, Artur Siekielski
<[EMAIL PROTECTED]> wrote:
>
> Hi.
> How can I use "...WHERE sth NOT IN (1, 4 ,5)" queries when using ORM
> quering? There is '_in' only and I don't see how can I pass negation
> to it. I tried to use general 'op' but I get these errors:
>
>>>> Session.query(Region).filter(Region.id.op('NOT IN')( [1,2,3] )).all()
>
> ProgrammingError: (ProgrammingError) syntax error at or near "ARRAY"
> LINE 3: WHERE "Region".id NOT IN ARRAY[1, 2, 3] ORDER BY "Region".id
>                                 ^
>  'SELECT "Region".id AS "Region_id", "Region".name AS "Region_name"
> \nFROM "Region" \nWHERE "Region".id NOT IN %(id_1)s ORDER BY
> "Region".id' {'id_1': [1, 2, 3]}
>
>
> (using tuple instead of a list)
>>>> Session.query(Region).filter(Region.id.op('NOT IN')( (1,2,3) )).all()
>
> (ProgrammingError) can't adapt 'SELECT "Region".id AS "Region_id",
> "Region".name AS "Region_name" \nFROM "Region" \nWHERE "Region".id NOT
> IN %(id_1)s ORDER BY "Region".id' {'id_1': (1, 2, 3)}
>
>
> (using string instead of a tuple)
>>>> Session.query(Region).filter(Region.id.op('NOT IN')( '(1,2,3)' )).all()
> ProgrammingError: (ProgrammingError) syntax error at or near
> "E'(1,2,3)'"
> LINE 3: WHERE "Region".id NOT IN E'(1,2,3)' ORDER BY "Region".id
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to