diff --git a/integration_tests/models/plugins/snowflake.yml b/integration_tests/models/plugins/snowflake.yml index f159395e..19681fa7 100644 --- a/integration_tests/models/plugins/snowflake.yml +++ b/integration_tests/models/plugins/snowflake.yml @@ -71,12 +71,20 @@ sources: - name: people_csv_partitioned_no_columns external: - <<: *json-people + <<: *csv-people partitions: *parts-of-the-people tests: *same-rowcount + + - name: people_csv_with_keyword_colname + external: *csv-people + columns: + - name: UNION + quote: true + data_type: varchar(64) + tests: *same-rowcount - name: people_json_unpartitioned_no_columns - external: *csv-people + external: *json-people tests: *same-rowcount - name: people_json_partitioned_no_columns diff --git a/macros/plugins/snowflake/create_external_table.sql b/macros/plugins/snowflake/create_external_table.sql index 26bb0833..30904403 100644 --- a/macros/plugins/snowflake/create_external_table.sql +++ b/macros/plugins/snowflake/create_external_table.sql @@ -15,12 +15,13 @@ {{partition.name}} {{partition.data_type}} as {{partition.expression}}{{- ',' if not loop.last or columns|length > 0 -}} {%- endfor -%}{%- endif -%} {%- for column in columns %} + {%- set column_quoted = adapter.quote(column.name) if column.quote else column.name %} {%- set col_expression -%} {%- if is_csv -%}nullif(value:c{{loop.index}},''){# special case: get columns by ordinal position #} {%- else -%}nullif(value:{{column.name}},''){# standard behavior: get columns by name #} {%- endif -%} {%- endset %} - {{column.name}} {{column.data_type}} as ({{col_expression}}::{{column.data_type}}) + {{column_quoted}} {{column.data_type}} as ({{col_expression}}::{{column.data_type}}) {{- ',' if not loop.last -}} {% endfor %} )