Re: [sqlalchemy] Using CTE without JOIN

2020-06-01 Thread Mike Bayer
thanks for the easy test. you want your IN to be against "SELECT * FROM cte" so you need to tell it to select() from that CTE: parent_cte = session.query(Parent).cte("parent_cte") query = ( session.query(Child).filter(Child.parent_id.in_(parent_cte.select())).all() ) if you just put the CTE in

[sqlalchemy] Using CTE without JOIN

2020-06-01 Thread Marat Sharafutdinov
from sqlalchemy import Column, ForeignKey, Integer, create_engine from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import sessionmaker Base = declarative_base() class Parent(Base): __tablename__ = 'parents' id = Column(Integer, primary_key=True) class