/
anton.boytsov
/
dbt_course_module2
Обзор
Документация
Войти
/
anton.boytsov
/
dbt_course_module2
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
macros/safe_select.sql
26 строк
658 B
Anton Boytsov
Module 8: test macros
08 май 2026, 14:52
08 май 2026, 14:52
12609a0
Код
Авторство
О чём код?
{% macro safe_select(table_name) %} {% set check_query %} select table_name from {{ target.database }}.information_schema.tables where table_schema = '{{ target.schema }}' and upper(table_name) = '{{ table_name.upper() }}' {% endset %} {% do log(check_query) %} {% set founded_table = run_query(check_query).columns[0].values() %} {% set final_query %} {% if founded_table %} select * from {{ table_name }} {% else %} select null {% endif %} {% endset %} {% do log(final_query, True) %} {% endmacro %}