pop icon indicating copy to clipboard operation
pop copied to clipboard

OR needed in SELECT query

Open briskt opened this issue 5 years ago • 2 comments

I'm finding a need for an OR in a SELECT query. Alternatives presently include:

  1. performing two separate queries and merging the data together
  2. using raw SQL
  3. other?

Complications:

  1. interleaving sorted data becomes difficult to implement and comes at a performance penalty
  2. generating IN (?) arguments for raw SQL adds additional app code, effectively duplicating work already accomplished in the Pop library
  3. 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.

briskt avatar Jan 24 '20 16:01 briskt

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?

duckbrain avatar Aug 13 '20 18:08 duckbrain

Could be considerable.

Related to #610 and some others including #777

sio4 avatar Sep 24 '22 09:09 sio4