Skip to content

Instantly share code, notes, and snippets.

@drewbanin
Created January 14, 2023 20:01
Show Gist options
  • Save drewbanin/a830a4694c9141adc7e6bfafe7818e63 to your computer and use it in GitHub Desktop.
Save drewbanin/a830a4694c9141adc7e6bfafe7818e63 to your computer and use it in GitHub Desktop.
{{
config(
materialized='incremental',
unique_key='id',
indexes=[
{'columns': ['id', 'name']},
]
)
}}
select
1 as id,
'drew' as name,
getdate() as dt
-- macros/index.sql
{% macro default__get_create_index_sql(relation, index_dict) -%}
{%- set index_config = adapter.parse_index(index_dict) -%}
{%- set comma_separated_columns = ", ".join(index_config.columns) -%}
{%- set index_name = index_config.render(relation) -%}
{%- do log('Creating an index on ' ~ relation ~ ' [' ~ comma_separated_columns ~ ']!', info=true) -%}
ALTER TABLE {{ relation }}
ADD CONSTRAINT "unique_{{ index_name }}"
UNIQUE ({{ comma_separated_columns }});
{%- endmacro %}
{{
config(
materialized='table',
indexes=[
{'columns': ['id', 'name']},
]
)
}}
select
1 as id,
'drew' as name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment