sqlalchemy使用内连接报错Please use the .select_from() method to establish an explicit left side, as well as

sqlalchemy.exc.InvalidRequestError: Don’t know how to join to <sqlalchemy.sql.selectable.Select object at 0x00000118E0DA2908>. Please use the .select_from() method to establish an explicit left side, as well as providing an explicit ON clause if not present already to help resolve the ambiguity.
错误提示信息意思大概是:
在这里插入图片描述

我的代码是:

            as= db.session.query(B.id).join(另一个查询语句, B.ancestors.like(
                func.find_in_set(item[1].ancestors, B.ancestors))).group_by(B.id).all()

            sql = as.statement.compile(compile_kwargs={"literal_binds": True})
            data = as.paginate(page=1, per_page=10, error_out=False)
            print(sql)

我想要另一个查询出来的查询语句得出来的表能够连接另一张表,想使用内连接,query是select语句中from,是来自哪张表的意思,总的来说我没弄懂基本概念就开始行动妄想搭建高层,join(内连接)和outerjoin(外连接)()中先写连接哪张表然后写on的条件,也就是连接的条件语句。

之后又出现错误:
sqlalchemy.exc.ArgumentError: Column expression or FROM clause expected, got <sqlalchemy.sql.selectable.Select object at 0x000002019FC8C448> object resolved from <flask_sqlalchemy.BaseQuery object at 0x000002019FBDE248> object. To create a FROM clause from a <class ‘sqlalchemy.sql.selectable.Select’> object, use the .subquery() method. (Background on this error at: http://sqlalche.me/e/14/89ve)

没理解对query的使用,ok这样写才是正确的:

		softwares = db.session.query(SoftwareModel, SoftwareAuth).outerjoin(
        SoftwareAuth,
        SoftwareAuth.software_id == SoftwareModel.id).outerjoin(
        DepartmentModel,
        SoftwareAuth.dept_id == DepartmentModel.id).filter(
        or_(func.find_in_set(dept[1].id, DepartmentModel.ancestors), DepartmentModel.id == dept[1].id,
            SoftwareModel.auth_type == 1), *filters
    ).paginate(page=res.page, per_page=res.limit, error_out=False)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值