Created
July 4, 2014 16:19
-
-
Save davidszotten/334e56e5125476090983 to your computer and use it in GitHub Desktop.
sqlalchemy `and` gotcha
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # `and` doesn't work unfortunately. | |
| # python doesn't allow overriding `and` behaviour | |
| >>> print Booking.id == 1 and Booking.id == 2 | |
| bookings.id = :id_1 | |
| >>> print and_(Booking.id == 1, Booking.id == 2) | |
| bookings.id = :id_1 AND bookings.id = :id_2 | |
| print (Booking.id == 1) & (Booking.id == 2) | |
| bookings.id = :id_1 AND bookings.id = :id_2 | |
| # & needs parens, has higher priority than ==, unlike `and` | |
| print (Booking.id == 1) and (Booking.id == 2) | |
| bookings.id = :id_1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment