Skip to content

Commit

Permalink
fix create table as macro
Browse files Browse the repository at this point in the history
Create table as cannot insert into relation due to missmatch column order between the result of sql
  • Loading branch information
viplazylmht committed Aug 10, 2022
1 parent d75d0ba commit 255e1ac
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,17 @@

on HASH( {{ get_qouted_csv_with_prefix("DBT_INTERNAL_DEST", unique_key) }} ) = HASH({{ get_qouted_csv_with_prefix("DBT_INTERNAL_SOURCE", unique_key) }})

when matched then update set
{% for column_name in merge_update_columns -%}
{{ adapter.quote(column_name) }} = DBT_INTERNAL_SOURCE.{{ adapter.quote(column_name) }}
{%- if not loop.last %}, {% endif %}
{%- endfor %}
{%- if merge_update_columns is string %}
{%- set merge_update_columns = merge_update_columns.split(',') %}
{% endif %}

{%- if merge_update_columns | length > 0 %}
when matched then update set
{% for column_name in merge_update_columns -%}
{{ adapter.quote(column_name) }} = DBT_INTERNAL_SOURCE.{{ adapter.quote(column_name) }}
{%- if not loop.last %}, {% endif %}
{%- endfor %}
{%- endif %}

when not matched then insert
({{ dest_columns_csv }})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@

insert into {{ relation }} ({{ dest_cols_csv }})
(
{{ sql }}
select {{ dest_cols_csv }} from (
{{ sql }}
) as DBT_MASKED_TARGET
);

{% endmacro %}
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pathlib

package_name = "dbt-vertica"
package_version = "1.0.3.1-rc2"
package_version = "1.0.3.1-rc3"
description = """The vertica adapter plugin for dbt (data build tool)"""

HERE = pathlib.Path(__file__).parent
Expand Down

0 comments on commit 255e1ac

Please sign in to comment.