I have the following code:

        tags = [u"tag1", u"tag2"]
        tag_count = len(tags)

        inner_q = select([shiptag_table.c.shipid])
        inner_w = inner_q.where(
            and_(shiptag_table.c.tagid == Tag.id,Tag.name.in_(tags))
        
).group_by(shiptag_table.c.shipid).having(func.count(shiptag_table.c.shipid)
== tag_count)

        outer_q = select([Tag.id, Tag.name,
func.count(shiptag_table.c.shipid)])
        outer_w = outer_q.where(
            and_(shiptag_table.c.shipid.in_(inner_w),
            not_(Tag.name.in_(tags)),
            Tag.id == shiptag_table.c.tagid)
        ).group_by(shiptag_table.c.tagid)

        related_tags = meta.Session.execute(outer_w).fetchall()
        return related_tags

If I try to execute as is, I get the following error:
InvalidRequestError: Select statement 'SELECT shiptag.shipid
FROM shiptag, tag
WHERE shiptag.tagid = tag.id AND tag.name IN (:name_1) GROUP BY
shiptag.shipid
HAVING count(shiptag.shipid) = :count_1' returned no FROM clauses due
to auto-correlation; specify c
orrelate(<tables>) to control correlation manually.
>>>

The inner_w select is claiming to not have any FROM clauses, though
they are clearly listed in the debug?
If I run the inner_w separate, not as a subselect, then feed the
results in to the in_ of outer_w it works.
I figure I have to be missing something obvious?
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to