sqlalchemy group_by gives error: column must appear in the GROUP BY clause or be used in an aggregate function

两盒软妹~` 提交于 2019-12-11 01:11:22

问题


Here's my query, simplified a little (some filters removed):

q = Foo.query.\
    join(Foo.bar).\
    with_entities(Bar.BAZ, Foo.BAT, ...).\
    group_by(Foo.BAT)

This gives me an error:

column "Bar.BAZ" must appear in the GROUP BY clause or be used in an aggregate function

It seems like there are questions on stackoverflow dealing with this error already, like this one, but what they're trying to do is sufficiently dissimilar to what I'm trying to do that I'm having a hard time understanding how their solutions apply and so I think it's alright for me to ask about this error again.

All I want is to group by one of the columns on Foo. Previously I was doing this in python, but I'd prefer to do it in postgres because I suspect it's faster.

来源:https://stackoverflow.com/questions/37798864/sqlalchemy-group-by-gives-error-column-must-appear-in-the-group-by-clause-or-be

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!