if dev/if prod SQL conditionals
if dev
and if prod
SQL conditionals 👇
Looker has a pair of conditional switches you can use in derived tables’ SQL, as well as most (maybe all?) SQL parameters:
-- if prod --
and
-- if dev --
As you can see these are SQL comments - you can add code after them that you want to be run only in prod or dev mode. When Looker generates its queries, it’ll remove one of them according to whether you’re in production or development mode so any code behind them will be included in the query.
The obvious use case for this is with PDTs, where you might want to add a date filter or other limit to the WHERE
part of a query so you don’t need to wait for a full build while developing. It also not limited to being used in a WHERE
clause. Since you can also use it in sql_table_name
you can also use it to reference different tables in dev vs production.
There is some more info in this (quite old) Looker community post, featuring an example in 'old' LookML! 👴🏻
This is another neat but possibly little-known Looker feature.