diff --git a/macros/utils/table_operations/delete_and_insert.sql b/macros/utils/table_operations/delete_and_insert.sql index 4672ef116..099e20be6 100644 --- a/macros/utils/table_operations/delete_and_insert.sql +++ b/macros/utils/table_operations/delete_and_insert.sql @@ -132,3 +132,26 @@ {% do return(queries) %} {% endmacro %} + +{% macro bigquery__get_delete_and_insert_queries(relation, insert_relation, delete_relation, delete_column_key) %} + {% set queries = [] %} + + {% if delete_relation %} + {% set delete_query %} + delete from {{ relation }} + where + {{ delete_column_key }} is null + or {{ delete_column_key }} in (select {{ delete_column_key }} from {{ delete_relation }}); + {% endset %} + {% do queries.append(delete_query) %} + {% endif %} + + {% if insert_relation %} + {% set insert_query %} + insert into {{ relation }} select * from {{ insert_relation }}; + {% endset %} + {% do queries.append(insert_query) %} + {% endif %} + + {% do return(queries) %} +{% endmacro %}