pop
pop copied to clipboard
OR needed in SELECT query
I'm finding a need for an OR in a SELECT query. Alternatives presently include:
- performing two separate queries and merging the data together
- using raw SQL
- other?
Complications:
- interleaving sorted data becomes difficult to implement and comes at a performance penalty
- generating
IN (?)arguments for raw SQL adds additional app code, effectively duplicating work already accomplished in the Pop library - I haven't thought of other alternatives. Suggestions?
If I were to create an OrWhere method in the query builder, would this be of value? I'm not promising anything, as I haven't a clue what I'd be getting myself into. Just wanted to check ahead of time to see if it would be accepted.
Having OR and AND adds the question of precedence. a AND b OR c can be interpreted (a AND b) OR c or a AND (b OR c).
I think the normal way of handling this is to have a more complex clause in your Where.
tx.Where("a_id = ? OR b_id = ?", idA, idB)
Where doesn't completely abstract the WHERE clause away from you, it handles it occurring multiple times if it does by ANDing them together.
Do you have a more specific example of what you want to OR together?
Could be considerable.
Related to #610 and some others including #777