forked from RealSelf/dbt-utils-source
-
Notifications
You must be signed in to change notification settings - Fork 0
/
star.sql
30 lines (22 loc) · 838 Bytes
/
star.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
{% macro star(from, except=[]) -%}
{#-- Prevent querying of db in parsing mode. This works because this macro does not create any new refs. #}
{%- if not execute -%}
{{ return('') }}
{% endif %}
{%- if from.name -%}
{%- set schema_name, table_name = from.schema, from.name -%}
{%- else -%}
{%- set schema_name, table_name = (from | string).split(".") -%}
{%- endif -%}
{%- set include_cols = [] %}
{%- set cols = adapter.get_columns_in_table(schema_name, table_name) -%}
{%- for col in cols -%}
{%- if col.column not in except -%}
{% set _ = include_cols.append(col.column) %}
{%- endif %}
{%- endfor %}
{%- for col in include_cols %}
"{{ col }}" {% if not loop.last %},
{% endif %}
{%- endfor -%}
{%- endmacro %}