Created
April 26, 2017 20:43
-
-
Save drewbanin/43db27d86d5857facb7fb4aef19cc7aa to your computer and use it in GitHub Desktop.
table indexes (postgres)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Macros to add indexes: | |
-- macros/indexes.sql | |
{% macro index(this, column) %} | |
drop index if exists "{{ this.schema }}"."{{ this.name }}__index_on_{{ column }}" cascade; | |
create index "{{ this.name }}__index_on_{{ column }}" on {{ this }} ("{{ column }}") | |
{% endmacro %} | |
{% macro unique_index(this, column) %} | |
drop index if exists "{{ this.schema }}"."{{ this.name }}__index_on_{{ column }}" cascade; | |
create unique index "{{ this.name }}__index_on_{{ column }}" on {{ this }} ("{{ column }}") | |
{% endmacro %} | |
-- Call them like this in your model code: | |
-- models/my_model.sql | |
{{ | |
config({ | |
"materialized": "table", | |
"post-hook": [ | |
"{{ unique_index(this, 'id') }}", | |
], | |
}) | |
}} | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment