Test table existence

What’s the recommended pattern to test for a table’s existence? Specifically, we have source tables that are generated outside of dbt, and we want to check whether they exist. Otherwise, dbt will create views of these source tables, but the views won’t reference any data.

I’m aware that there’s a way to do this in a package, but I’m not seeing a model test that can be added in the .yml file. I’m not seeing any source properties that could be used. And data tests succeed when the query returns 0, so a select count(*) limit 1 can’t be used.

Hey @random_pecan — the approach for packages should work for projects too! We just don’t typically see people implementing conditional logic like this in their company’s dbt project. I’d love to understand your use case a little better: why does the table exist sometimes but not others? How frequently do they disappear? Is this a one off or a common thing? And how predictable is it when it happens? (Lots of questions!)