Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add alter_column_type macro #64

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## v.0.21

### Fixes

- Resolves bug for running incremental models where the macro `alter_column_type` had incorrect syntax

## v.0.20.0

### Features
Expand Down
17 changes: 16 additions & 1 deletion dbt/include/synapse/macros/adapters.sql
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
{# TODO instead of deleting it... #}
{% macro synapse__rename_relation(from_relation, to_relation) -%}
{% call statement('rename_relation') -%}

rename object {{ from_relation.include(database=False) }} to {{ to_relation.identifier }}
{%- endcall %}
{% endmacro %}
Expand Down Expand Up @@ -158,3 +158,18 @@
{% set table = load_result('get_columns_in_relation').table %}
{{ return(sql_convert_columns_in_relation(table)) }}
{% endmacro %}

{% macro synapse__alter_column_type(relation, column_name, new_column_type) %}

{%- set tmp_column = column_name + "__dbt_alter" -%}

{% call statement('alter_column_type') -%}

alter {{ relation.type }} {{ relation }} add {{ tmp_column }} {{ new_column_type }};
update {{ relation }} set {{ tmp_column }} = {{ column_name }};
alter {{ relation.type }} {{ relation }} drop column {{ column_name }};
exec sp_rename '{{ relation | replace('"', '') }}.{{ tmp_column }}', '{{ column_name }}', 'column'

{%- endcall -%}

{% endmacro %}