I have a scenario where I’m rolling out some boilerplate code to multiple customers and I want to be able to reference a model that may or may not exist at a specific customer. I’m attempting to do something like the following:
{% if ref("_test_stg__model2") is not none %}
{% set model_to_use = "_test_stg__model2"%}
{% else %}
{% set model_to_use = "_test_stg__model1"%}
{% endif %}
select * from {{ref(model_to_use)}}
This returns an error because only model1 exists and model2 does not. I want this to execute model1 when model2 does not exist.
Has anybody done something similar to this before that can put me on the right track?
Brilliant thank you! That gives me some challenges with database and schema name being hardcoded rather than using ref() but I think I can probably work around those.