That's incredibly strange, because I ran your exact code and got this
for output

SELECT follows.friend_id
FROM follows, (SELECT users.id AS id
FROM users) AS anon_1
WHERE follows.friend_id NOT IN SELECT users.id
FROM users

I checked which version of SA I was running and it was 0.5.2

Upgraded it 0.5.3, and now I get the correct output. I had assumed I
was running the latest because I did a clean install a couple weeks
ago.

I am guessing it was something fixed in the latest version. Sorry for
the bother.


Thanks,
Mike

On Apr 28, 7:47 am, "Michael Bayer" <[email protected]> wrote:
> cant reproduce.
>
> test case:
>
> from sqlalchemy import *
> from sqlalchemy.orm import *
> from sqlalchemy.ext.declarative import declarative_base
>
> metadata = MetaData()
> Base = declarative_base(metadata=metadata)
>
> class User(Base):
>     __tablename__ = 'users'
>     id = Column(Integer, primary_key=True)
>
> follows_table = Table('follows', metadata, Column('friend_id'))
>
> Session = sessionmaker()()
> subquery = Session.query(User.id).subquery()
>
> q =
> follows_table.select().where(not_(follows_table.c.friend_id.in_(subquery)))
>
> print q
>
> output:
>
> SELECT follows.friend_id
> FROM follows
> WHERE follows.friend_id NOT IN (SELECT users.id
> FROM users)
>
> Mike Lewis wrote:
>
> > Hi,
>
> > This might be a noob question, but I am trying to reproduce the
> > following sql query in SA
>
> > select user_id, friend_id from follows  where friend_id not (in select
> > id from users);
>
> > First, I do this:
> > subquery = Session.query(User.id).subquery()
>
> > Then
> > q = follows_table.select().where(not_(follows_table.c.friend_id.in_
> > (subquery)))
>
> > q turns into:
> > SELECT follows.user_id, follows.friend_id
> > FROM follows, (SELECT users.id AS id
> > FROM users) AS anon_1
> > WHERE follows.friend_id NOT IN SELECT users.id
> > FROM users
>
> > I'm not really sure where the first subselect comes from. Also, it
> > isn't a valid query in postgres because the second SELECT users.id
> > FROM users needs to be in parens.
>
> > Am I missing something?
>
> > Thanks,
> > Mike
--~--~---------~--~----~------------~-------~--~----~
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