I’m looking for a way to have my Explore’s generated SQL include a WHERE clause that includes OR logic.
This wouldn’t be:
... WHERE (field1 = 'user_value') AND (field2 = 'hard-coded value 1' OR field3 = 'hard-coded value 2'
Rather, it would be:
... WHERE (field1 = 'user_value') OR (whatever-I-want)
The documentation for sql_where states:
If you forgot to add the parentheses in this example, and a user added their own filter, the generated
WHEREclause could have the form:> >auto> WHERE> user_filter = 'something' AND> region = 'Northeast' OR> company = 'Periaptly'> >> > In this situation, the filter that the user applied may not work. No matter what, rows withcompany = 'Periaptly'will show up, because the AND condition is evaluated first. Without parentheses, only part of thesql_wherecondition combines with the user’s filter.
That’s exactly what I want!! But neither sql_where nor sql_always_where behave that way in reality!
Is there any other way to get the behavior I want? I want to fully override the SQL WHERE clause with a custom behavior of my choosing. I have some pre-filtered derived tables, each containing rows that are filtered according to table-specific fields, and I essentially want to show all rows where the table-specific filters are met. Columns not appearing in one table at all will show up as NULL in the final results; I am OK with that, it’s the expected behavior – any filters on that field should only limit results that come from that table’s source.
The only way I can think to achieve the desired behavior is to switch to using Liquid for EVERYTHING, and having separate dimensions for both “things to include in the result table” (can_filter:no) and filter-only fields (Liquid) and manually applying all of the filters by hand. That’s neither very good for maintainability nor clear to the user (“why can’t I just filter on X like I’m used to?”)… There must be a better way.
I saw some google results for a post titled “filtering between multiple fields with or using a yesno dimension”, but it looks like that post is no longer available. Not sure if it’d help or not…
What I essentially want to do is include an “OR TRUE” (no parenthesis) in the main query’s WHERE clause. Having the end-user use a custom filter with the relevant OR logic is not a viable option… The OR is implied by the nature of what I’m doing.
I could make some kind of a join where each row includes the results from its “source table” plus the results from the most recent [matching] row of each other table, but that’s both non-performant and confusing to the user: NULL is more straightforward to the user than including some “nearby data”.
Thanks in advance for any help!