Created
February 22, 2021 18:24
-
-
Save TAJD/38cf35819f98831af98de60b9927befe to your computer and use it in GitHub Desktop.
dbt macro to create table from dbt model
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
{% 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