2016-03-08 47 views
0

我想基於像這樣的表達式過濾我的查詢多種選擇:SQLAlchemy的多個AND表達式創建於同一條目

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

但是,當我將其過濾,查詢增加了SELECT語句兩次,這在MYSQL導致OperationalError:1060「重複的列名‘XXXX’這裏是我的SQLAlchemy的表達:

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

時,我有比之一,我纔能有分割字符串更表達更多時纔會發生。清楚地看到重複選擇。它在t中是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'] 

任何幫助將不勝感激,謝謝!

回答

0

我想通了。 BinaryExpression實際上有兩個表達式子句,所以第二個子句創建了另一個選擇。