Skip to content

Appending condition to existing WHERE clause #263

Closed Answered by tobymao
dibsonmuad asked this question in Q&A
Discussion options

You must be logged in to vote

You can just call where on the select statement.

>>> parse_one("select * from x where y = 'blah' group by x").where("z = foo").sql()
"SELECT * FROM x WHERE y = 'blah' AND z = foo GROUP BY x"

this defaults to AND, if you want to rewrite the Where, you can do

>>> parse_one("select * from x where y = 'blah' group by x").where("z = foo or y = 'blah'", append=False).sql()
"SELECT * FROM x WHERE z = foo OR y = 'blah' GROUP BY x"

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@dibsonmuad
Comment options

Answer selected by tobymao
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants