Skip to content

Commit ae65d05

Browse files
AesthetjlcotoTaras Stetsiak
authored
Added case for handling postgres foreign tables... (#476)
* Add link for fewer_rows_than schema test in docs (#465) * Added case for handling postgres foreign tables (tables which are external to current database and are imported into current database from remote data stores by using Foreign Data Wrappers functionallity). * Reworked getting of postges table_type. * Added needed changes to CHANGELOG. Co-authored-by: José Coto <jlcoto@users.noreply.github.com> Co-authored-by: Taras Stetsiak <tstetsiak@health-union.com>
1 parent 900365a commit ae65d05

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,16 @@
1414
## 🚨 Breaking changes
1515
- dbt ONE POINT OH is here! This version of dbt-utils requires _any_ version (minor and patch) of v1, which means far less need for compatibility releases in the future.
1616
- The partition column in the `mutually_exclusive_ranges` test is now always called `partition_by_col`. This enables compatibility with `--store-failures` when multiple columns are concatenated together. If you have models built on top of the failures table, update them to reflect the new column name. ([#423](https://github.com/dbt-labs/dbt-utils/issues/423), [#430](https://github.com/dbt-labs/dbt-utils/pull/430))
17+
18+
## Fixes
19+
- `get_relations_by_pattern()` now uses additional sub macros `get_table_types_sql()` to determine table types for different database engines. ([#357](https://github.com/dbt-labs/dbt-utils/issues/357), [#476](https://github.com/dbt-labs/dbt-utils/pull/476))
20+
1721
## Under the hood
1822
- make date_spine macro compatible with the Athena connector (#462)
23+
1924
## Contributors:
2025
- [codigo-ergo-sum](https://github.com/codigo-ergo-sum) (#430)
26+
- [Aesthet](https://github.com/Aesthet) (#476)
2127

2228
# dbt-utils 0.7.5
2329
🚨 This is a compatibility release in preparation for `dbt-core` v1.0.0 (🎉). Projects using dbt-utils 0.7.4 with dbt-core v1.0.0 can expect to see a deprecation warning. This will be resolved in dbt_utils v0.8.0.

macros/sql/get_table_types_sql.sql

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{%- macro get_table_types_sql() -%}
2+
{{ return(adapter.dispatch('get_table_types_sql', 'dbt_utils')()) }}
3+
{%- endmacro -%}
4+
5+
{% macro default__get_table_types_sql() %}
6+
case table_type
7+
when 'BASE TABLE' then 'table'
8+
when 'EXTERNAL TABLE' then 'external'
9+
when 'MATERIALIZED VIEW' then 'materializedview'
10+
else lower(table_type)
11+
end as "table_type"
12+
{% endmacro %}
13+
14+
15+
{% macro postgres__get_table_types_sql() %}
16+
case table_type
17+
when 'BASE TABLE' then 'table'
18+
when 'FOREIGN' then 'external'
19+
when 'MATERIALIZED VIEW' then 'materializedview'
20+
else lower(table_type)
21+
end as "table_type"
22+
{% endmacro %}

macros/sql/get_tables_by_pattern_sql.sql

+1-6
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,7 @@
88
select distinct
99
table_schema as "table_schema",
1010
table_name as "table_name",
11-
case table_type
12-
when 'BASE TABLE' then 'table'
13-
when 'EXTERNAL TABLE' then 'external'
14-
when 'MATERIALIZED VIEW' then 'materializedview'
15-
else lower(table_type)
16-
end as "table_type"
11+
{{ dbt_utils.get_table_types_sql() }}
1712
from {{ database }}.information_schema.tables
1813
where table_schema ilike '{{ schema_pattern }}'
1914
and table_name ilike '{{ table_pattern }}'

0 commit comments

Comments
 (0)