Skip to content

Instantly share code, notes, and snippets.

@TAJD
Created February 22, 2021 18:24
Show Gist options
  • Save TAJD/38cf35819f98831af98de60b9927befe to your computer and use it in GitHub Desktop.
Save TAJD/38cf35819f98831af98de60b9927befe to your computer and use it in GitHub Desktop.
dbt macro to create table from dbt model
{% macro create_table(table_name) %}
{% set sql %}
BEGIN;
DROP TABLE IF EXISTS {{ table_name[:-4] }};
CREATE TABLE {{ table_name[:-4] }} AS SELECT * FROM {{ table_name }};
GRANT SELECT ON {{ table_name[:-4] }} TO webview;
COMMIT;
{% endset %}
{% do run_query(sql) %}
{% do log(table_name+" table created", info=True) %}
{% endmacro %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment