Skip to content

Commit

Permalink
handle cased databases properly on pg/rs
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob Beck committed Nov 19, 2019
1 parent 099adf9 commit 2869467
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
11 changes: 6 additions & 5 deletions core/dbt/adapters/base/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,18 @@ def schemas_searched(self):
def flatten(self):
new = self.__class__()

database = None
# iterate once to look for a database name
# make sure we don't have duplicates
seen = {r.database.lower() for r in self if r.database}
if len(seen) > 1:
dbt.exceptions.raise_compiler_error(str(seen))
elif len(seen) == 1:
database = list(seen)[0]

for information_schema_name, schema in self.search():
path = {
'database': information_schema_name.database,
'schema': schema
}
new.add(information_schema_name.incorporate(
path={'database': database, 'schema': schema},
path=path,
quote_policy={'database': False},
include_policy={'database': False},
))
Expand Down
4 changes: 2 additions & 2 deletions plugins/postgres/dbt/include/postgres/macros/adapters.sql
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@
{% macro postgres__list_relations_without_caching(information_schema, schema) %}
{% call statement('list_relations_without_caching', fetch_result=True) -%}
select
'{{ information_schema.database.lower() }}' as database,
'{{ information_schema.database }}' as database,
tablename as name,
schemaname as schema,
'table' as type
from pg_tables
where schemaname ilike '{{ schema }}'
union all
select
'{{ information_schema.database.lower() }}' as database,
'{{ information_schema.database }}' as database,
viewname as name,
schemaname as schema,
'view' as type
Expand Down

0 comments on commit 2869467

Please sign in to comment.