gpt4 book ai didi

python - SQLAlchemy 多个 AND 表达式在同一条目上创建多个选择

转载 作者:行者123 更新时间:2023-11-29 21:16:49 25 4
gpt4 key购买 nike

我正在尝试根据如下表达式过滤我的查询:

self.query = self.query.filter(expression)

但是当我过滤它时,查询会添加两次 select 语句,这在 MYSQL 中会导致操作错误:1060“重复列名'xxxx'。这是我的 SQLAlchemy 表达式:

'"var__490__07McUdXtiy".response IS NOT NULL AND "var__490__07McUdXtiy".response != :param_1 AND "var__490__07McUdXtiy".response = :param_2'

只有当表达式中有多个 AND 时才会发生这种情况。我已经分割了字符串以便更清楚地看到重复的选择。下面的结果是 var__490__07McUdXtiy:

['SELECT auth_user.id AS auth_user_id',
' auth_user.password AS auth_user_password',
' auth_user.last_login AS auth_user_last_login',
' auth_user.is_superuser AS auth_user_is_superuser',
' auth_user.username AS auth_user_username',
' auth_user.first_name AS auth_user_first_name',
' auth_user.last_name AS auth_user_last_name',
' auth_user.email AS auth_user_email',
' auth_user.is_staff AS auth_user_is_staff',
' auth_user.is_active AS auth_user_is_active',
' auth_user.date_joined AS auth_user_date_joined',
' `var__490__07McUdXtiy`.response AS `07McUdXtiy_short`',
' `var__490__07McUdXtiy`.response AS `07McUdXtiy_short` \nFROM auth_user INNER JOIN reviewroom_reviewroomgroup_members ON reviewroom_reviewroomgroup_members.user_id = auth_user.id AND reviewroom_reviewroomgroup_members.reviewroomgroup_id IN (%s',
' %s) LEFT OUTER JOIN surveys_responsegroup AS survey__490 ON survey__490.user_id = auth_user.id AND survey__490.deleted = %s AND survey__490.survey_id = %s LEFT OUTER JOIN surveys_response AS `var__490__07McUdXtiy` ON `var__490__07McUdXtiy`.group_id = survey__490.id AND `var__490__07McUdXtiy`.question = %s \nWHERE `var__490__07McUdXtiy`.response IS NOT NULL AND `var__490__07McUdXtiy`.response != %s AND `var__490__07McUdXtiy`.response = %s']

如有任何帮助,我们将不胜感激,谢谢!

最佳答案

我明白了。 BinaryExpression 实际上有两个表达式子句,因此第二个子句创建了另一个选择。

关于python - SQLAlchemy 多个 AND 表达式在同一条目上创建多个选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35872981/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com