Is explicit CROSS JOIN possible with SQLAlchemy?

后端 未结 2 986
旧巷少年郎
旧巷少年郎 2021-01-20 01:59

Is it possible to generate an explicit CROSS JOIN query with SQLAlchemy as the following example:

SELECT * 
FROM foo 
CROSS JOIN bar

And if

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-20 02:45

    You can make cartesian product using inner join, applying condition which is always true. E.g. for SQLAlchemy ORM:

    from sqlalchemy.sql.expression import literal
    
    session.query(Foo, Bar).join(Bar, literal(True)).all()
    

    There're only join and outerjoin functions in SQLAlchemy for now (v0.9).

提交回复
热议问题