SQLAlchemy Conjunction with Parentheses -
i trying produce below sql in sqlalchemy core. not able parentheses in conjunction , or appear.
select member t1 inner join member t2 on ( ( t1.first_name = t2.last_name , t1.last_name = t2.first_name , t1.dob = t2.dob ) or ( t1.last_name = t2.last_name , t1.first_name = t2.first_name , t1.dob = t2.dob ) ) group t2.id
the sqlalchemy core statement using is:
selstmt = select([t1]).select_from( t1.join( t2, or_( and_( t1.c.first_name == t2.c.last_name, t1.c.last_name == t2.c.first_name, t1.c.dob == t2.c.dob ), and_( t1.c.last_name == t2.c.last_name, t1.c.first_name == t2.c.first_name, t1.c.dob == t2.c.dob ) ) ) ).group_by(t2.c.id)
the resulting sql code is:
select t1 t1 join t2 on t1.first_name = t2.last_name , t1.last_name = t2.first_name , t1.dob = t2.dob or t1.last_name = t2.last_name , t1.first_name = t2.first_name , t1.dob = t2.dob group t2.id
since parentheses not included logic not correct. how parentheses in conjunctions?
apparently , operation has higher precedence on or. therefore in case parentheses not required.
Comments
Post a Comment