diff --git a/core/dbt/include/global_project/macros/core.sql b/core/dbt/include/global_project/macros/core.sql index a152cd76cec..5051c5cb062 100644 --- a/core/dbt/include/global_project/macros/core.sql +++ b/core/dbt/include/global_project/macros/core.sql @@ -1,6 +1,6 @@ {% macro statement(name=None, fetch_result=False, auto_begin=True) -%} {%- if execute: -%} - {%- set sql = render(caller()) -%} + {%- set sql = caller() -%} {%- if name == 'main' -%} {{ log('Writing runtime SQL for node "{}"'.format(model['unique_id'])) }} @@ -16,7 +16,7 @@ {%- endmacro %} {% macro noop_statement(name=None, status=None, res=None) -%} - {%- set sql = render(caller()) -%} + {%- set sql = caller() -%} {%- if name == 'main' -%} {{ log('Writing runtime SQL for node "{}"'.format(model['unique_id'])) }} diff --git a/core/dbt/include/global_project/macros/materializations/helpers.sql b/core/dbt/include/global_project/macros/materializations/helpers.sql index da78eb93506..dc21ac5d3ba 100644 --- a/core/dbt/include/global_project/macros/materializations/helpers.sql +++ b/core/dbt/include/global_project/macros/materializations/helpers.sql @@ -5,9 +5,12 @@ commit; {% endcall %} {% endif %} - {% call statement(auto_begin=inside_transaction) %} - {{ hook.get('sql') }} - {% endcall %} + {% set rendered = render(hook.get('sql')) | trim %} + {% if (rendered | length) > 0 %} + {% call statement(auto_begin=inside_transaction) %} + {{ rendered }} + {% endcall %} + {% endif %} {% endfor %} {% endmacro %}