Skip to content

Commit

Permalink
Surround in a transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
VersusFacit committed Feb 24, 2024
1 parent 5c9a3fe commit 8a31975
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions dbt/include/redshift/macros/materializations/table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,19 @@
{% if existing_relation is not none %}
{% if existing_relation.can_be_renamed %}
{{ adapter.rename_relation(existing_relation, backup_relation) }}
{{ adapter.rename_relation(intermediate_relation, target_relation) }}

{% else %}
drop table if exists {{ existing_relation }} cascade;
alter table {{ intermediate_relation }} rename to {{ target_relation }}
BEGIN
drop table if exists {{ existing_relation }} cascade;
alter table {{ intermediate_relation }} rename to {{ target_relation }}
{{ adapter.commit() }}
{% endif %}
{% endif %}
{% else %}
{{ adapter.rename_relation(intermediate_relation, target_relation) }}
{% endif %}

{{ adapter.rename_relation(intermediate_relation, target_relation) }}

{% do create_indexes(target_relation) %}

{{ run_hooks(post_hooks, inside_transaction=True) }}
Expand Down

0 comments on commit 8a31975

Please sign in to comment.