Skip to content

Commit

Permalink
do it the same as in trino
Browse files Browse the repository at this point in the history
  • Loading branch information
rloredo committed Jan 3, 2025
1 parent fe70b94 commit 044d5a8
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions macros/utils/table_operations/delete_and_insert.sql
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,24 @@
{% endmacro %}

{% macro bigquery__get_delete_and_insert_queries(relation, insert_relation, delete_relation, delete_column_key) %}
{% set query %}
{% if delete_relation %}
{% 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 }});
{% endif %}
{% if insert_relation %}
{% endset %}
{% do queries.append(delete_query) %}
{% endif %}

{% if insert_relation %}
{% set insert_query %}
insert into {{ relation }} select * from {{ insert_relation }};
{% endif %}
{% endset %}
{% do return([query]) %}
{% endset %}
{% do queries.append(insert_query) %}
{% endif %}

{% do return(queries) %}
{% endmacro %}

0 comments on commit 044d5a8

Please sign in to comment.