Skip to content

Commit

Permalink
use pg_catalog.svv_columns to load columns info (#89)
Browse files Browse the repository at this point in the history
To support redshift external tables and late binding views we need
additionally pull info from pg_catalog.svv_columns. Ref: https://github.com/dbt-labs/dbt-redshift/blob/fe91015ac6361c48531b439ac72d3f477d9cc07b/dbt/include/redshift/macros/adapters.sql
  • Loading branch information
Kostiantyn Liepieshov authored Aug 21, 2022
1 parent 186f398 commit d8a2dfc
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions macros/meta/information_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,43 @@
{% macro redshift__get_monitored_columns(table_schema, db_name) %}

{%- call statement('columns', fetch_result=True) -%}
with bound_views as (
select
table_name,
table_schema,
table_catalog,
column_name,
data_type,
is_nullable
from
{% if db_name %}{{db_name}}.{% endif %} information_schema.columns
),
external_views as (
select
table_name,
table_schema,
table_catalog,
column_name,
data_type,
is_nullable
from
pg_catalog.svv_columns
),
unioned as (
select * from bound_views
union all
select * from external_views
)

select
column_name,
data_type,
table_name,
table_schema,
table_catalog,
column_name,
data_type,
is_nullable
from
{% if db_name %}{{db_name}}.{% endif %}information_schema.columns
from
unioned
where
table_schema = '{{ table_schema }}'
{% endcall %}
Expand Down

0 comments on commit d8a2dfc

Please sign in to comment.