We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Issue with caching when views outside of dbt schemas select from dbt-managed schemas
## Issue

### Issue description
dbt's caching will fail hard on PG/Redshift if there exists a view _outside_ of a dbt-controlled schema that depends on a relation _inside_ of a dbt controlled schema.

### Results
```
InternalException: Cache inconsistency detected: in add_link, dependent link key _ReferenceKey(schema=u'dbt_airflow_events', identifier=u'tracking_l30d') not in cache!
```

### System information
The output of `dbt --version`:
```
0.12.0
```

### Steps to reproduce

1. Create and run an example model
```
-- models/test_it.sql

select 1 as id
```

2. Run the model
```
dbt run
```

3. Create an external dependency on this model
```
create schema debug;
create view debug.debug as (
  select * from analytics.test_it -- the model created above
)
```

4. Run dbt again
```
# this will fail
dbt run
```

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `dbt/adapters/postgres/impl.py`
Content:
```
1 import psycopg2
2 
3 from contextlib import contextmanager
4 
5 import dbt.adapters.default
6 import dbt.compat
7 import dbt.exceptions
8 import agate
9 
10 from dbt.logger import GLOBAL_LOGGER as logger
11 
12 
13 GET_RELATIONS_OPERATION_NAME = 'get_relations_data'
14 
15 
16 class PostgresAdapter(dbt.adapters.default.DefaultAdapter):
17 
18     DEFAULT_TCP_KEEPALIVE = 0  # 0 means to use the default value
19 
20     @contextmanager
21     def exception_handler(self, sql, model_name=None, connection_name=None):
22         try:
23             yield
24 
25         except psycopg2.DatabaseError as e:
26             logger.debug('Postgres error: {}'.format(str(e)))
27 
28             try:
29                 # attempt to release the connection
30                 self.release_connection(connection_name)
31             except psycopg2.Error:
32                 logger.debug("Failed to release connection!")
33                 pass
34 
35             raise dbt.exceptions.DatabaseException(
36                 dbt.compat.to_string(e).strip())
37 
38         except Exception as e:
39             logger.debug("Error running SQL: %s", sql)
40             logger.debug("Rolling back transaction.")
41             self.release_connection(connection_name)
42             raise dbt.exceptions.RuntimeException(e)
43 
44     @classmethod
45     def type(cls):
46         return 'postgres'
47 
48     @classmethod
49     def date_function(cls):
50         return 'datenow()'
51 
52     @classmethod
53     def get_status(cls, cursor):
54         return cursor.statusmessage
55 
56     @classmethod
57     def get_credentials(cls, credentials):
58         return credentials
59 
60     @classmethod
61     def open_connection(cls, connection):
62         if connection.state == 'open':
63             logger.debug('Connection is already open, skipping open.')
64             return connection
65 
66         base_credentials = connection.credentials
67         credentials = cls.get_credentials(connection.credentials.incorporate())
68         kwargs = {}
69         keepalives_idle = credentials.get('keepalives_idle',
70                                           cls.DEFAULT_TCP_KEEPALIVE)
71         # we don't want to pass 0 along to connect() as postgres will try to
72         # call an invalid setsockopt() call (contrary to the docs).
73         if keepalives_idle:
74             kwargs['keepalives_idle'] = keepalives_idle
75 
76         try:
77             handle = psycopg2.connect(
78                 dbname=credentials.dbname,
79                 user=credentials.user,
80                 host=credentials.host,
81                 password=credentials.password,
82                 port=credentials.port,
83                 connect_timeout=10,
84                 **kwargs)
85 
86             connection.handle = handle
87             connection.state = 'open'
88         except psycopg2.Error as e:
89             logger.debug("Got an error when attempting to open a postgres "
90                          "connection: '{}'"
91                          .format(e))
92 
93             connection.handle = None
94             connection.state = 'fail'
95 
96             raise dbt.exceptions.FailedToConnectException(str(e))
97 
98         return connection
99 
100     def cancel_connection(self, connection):
101         connection_name = connection.name
102         pid = connection.handle.get_backend_pid()
103 
104         sql = "select pg_terminate_backend({})".format(pid)
105 
106         logger.debug("Cancelling query '{}' ({})".format(connection_name, pid))
107 
108         _, cursor = self.add_query(sql, 'master')
109         res = cursor.fetchone()
110 
111         logger.debug("Cancel query '{}': {}".format(connection_name, res))
112 
113     # DATABASE INSPECTION FUNCTIONS
114     # These require the profile AND project, as they need to know
115     # database-specific configs at the project level.
116     def alter_column_type(self, schema, table, column_name,
117                           new_column_type, model_name=None):
118         """
119         1. Create a new column (w/ temp name and correct type)
120         2. Copy data over to it
121         3. Drop the existing column (cascade!)
122         4. Rename the new column to existing column
123         """
124 
125         relation = self.Relation.create(
126             schema=schema,
127             identifier=table,
128             quote_policy=self.config.quoting
129         )
130 
131         opts = {
132             "relation": relation,
133             "old_column": column_name,
134             "tmp_column": "{}__dbt_alter".format(column_name),
135             "dtype": new_column_type
136         }
137 
138         sql = """
139         alter table {relation} add column "{tmp_column}" {dtype};
140         update {relation} set "{tmp_column}" = "{old_column}";
141         alter table {relation} drop column "{old_column}" cascade;
142         alter table {relation} rename column "{tmp_column}" to "{old_column}";
143         """.format(**opts).strip()  # noqa
144 
145         connection, cursor = self.add_query(sql, model_name)
146 
147         return connection, cursor
148 
149     def _link_cached_relations(self, manifest, schemas):
150         try:
151             table = self.run_operation(manifest, GET_RELATIONS_OPERATION_NAME)
152         finally:
153             self.release_connection(GET_RELATIONS_OPERATION_NAME)
154         table = self._relations_filter_table(table, schemas)
155 
156         for (refed_schema, refed_name, dep_schema, dep_name) in table:
157             referenced = self.Relation.create(schema=refed_schema,
158                                               identifier=refed_name)
159             dependent = self.Relation.create(schema=dep_schema,
160                                              identifier=dep_name)
161             self.cache.add_link(dependent, referenced)
162 
163     def _list_relations(self, schema, model_name=None):
164         sql = """
165         select tablename as name, schemaname as schema, 'table' as type from pg_tables
166         where schemaname ilike '{schema}'
167         union all
168         select viewname as name, schemaname as schema, 'view' as type from pg_views
169         where schemaname ilike '{schema}'
170         """.format(schema=schema).strip()  # noqa
171 
172         connection, cursor = self.add_query(sql, model_name, auto_begin=False)
173 
174         results = cursor.fetchall()
175 
176         return [self.Relation.create(
177             database=self.config.credentials.dbname,
178             schema=_schema,
179             identifier=name,
180             quote_policy={
181                 'schema': True,
182                 'identifier': True
183             },
184             type=type)
185                 for (name, _schema, type) in results]
186 
187     def get_existing_schemas(self, model_name=None):
188         sql = "select distinct nspname from pg_namespace"
189 
190         connection, cursor = self.add_query(sql, model_name, auto_begin=False)
191         results = cursor.fetchall()
192 
193         return [row[0] for row in results]
194 
195     def check_schema_exists(self, schema, model_name=None):
196         sql = """
197         select count(*) from pg_namespace where nspname = '{schema}'
198         """.format(schema=schema).strip()  # noqa
199 
200         connection, cursor = self.add_query(sql, model_name,
201                                             auto_begin=False)
202         results = cursor.fetchone()
203 
204         return results[0] > 0
205 
206     @classmethod
207     def convert_text_type(cls, agate_table, col_idx):
208         return "text"
209 
210     @classmethod
211     def convert_number_type(cls, agate_table, col_idx):
212         decimals = agate_table.aggregate(agate.MaxPrecision(col_idx))
213         return "float8" if decimals else "integer"
214 
215     @classmethod
216     def convert_boolean_type(cls, agate_table, col_idx):
217         return "boolean"
218 
219     @classmethod
220     def convert_datetime_type(cls, agate_table, col_idx):
221         return "timestamp without time zone"
222 
223     @classmethod
224     def convert_date_type(cls, agate_table, col_idx):
225         return "date"
226 
227     @classmethod
228     def convert_time_type(cls, agate_table, col_idx):
229         return "time"
230
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/dbt/adapters/postgres/impl.py b/dbt/adapters/postgres/impl.py
--- a/dbt/adapters/postgres/impl.py
+++ b/dbt/adapters/postgres/impl.py
@@ -158,7 +158,10 @@
                                               identifier=refed_name)
             dependent = self.Relation.create(schema=dep_schema,
                                              identifier=dep_name)
-            self.cache.add_link(dependent, referenced)
+
+            # don't record in cache if this relation isn't in a relevant schema
+            if refed_schema.lower() in schemas:
+                self.cache.add_link(dependent, referenced)
 
     def _list_relations(self, schema, model_name=None):
         sql = """

{"golden_diff": "diff --git a/dbt/adapters/postgres/impl.py b/dbt/adapters/postgres/impl.py\n--- a/dbt/adapters/postgres/impl.py\n+++ b/dbt/adapters/postgres/impl.py\n@@ -158,7 +158,10 @@\n                                               identifier=refed_name)\n             dependent = self.Relation.create(schema=dep_schema,\n                                              identifier=dep_name)\n-            self.cache.add_link(dependent, referenced)\n+\n+            # don't record in cache if this relation isn't in a relevant schema\n+            if refed_schema.lower() in schemas:\n+                self.cache.add_link(dependent, referenced)\n \n     def _list_relations(self, schema, model_name=None):\n         sql = \"\"\"\n", "issue": "Issue with caching when views outside of dbt schemas select from dbt-managed schemas\n## Issue\r\n\r\n### Issue description\r\ndbt's caching will fail hard on PG/Redshift if there exists a view _outside_ of a dbt-controlled schema that depends on a relation _inside_ of a dbt controlled schema.\r\n\r\n### Results\r\n```\r\nInternalException: Cache inconsistency detected: in add_link, dependent link key _ReferenceKey(schema=u'dbt_airflow_events', identifier=u'tracking_l30d') not in cache!\r\n```\r\n\r\n### System information\r\nThe output of `dbt --version`:\r\n```\r\n0.12.0\r\n```\r\n\r\n### Steps to reproduce\r\n\r\n1. Create and run an example model\r\n```\r\n-- models/test_it.sql\r\n\r\nselect 1 as id\r\n```\r\n\r\n2. Run the model\r\n```\r\ndbt run\r\n```\r\n\r\n3. Create an external dependency on this model\r\n```\r\ncreate schema debug;\r\ncreate view debug.debug as (\r\n  select * from analytics.test_it -- the model created above\r\n)\r\n```\r\n\r\n4. Run dbt again\r\n```\r\n# this will fail\r\ndbt run\r\n```\n", "before_files": [{"content": "import psycopg2\n\nfrom contextlib import contextmanager\n\nimport dbt.adapters.default\nimport dbt.compat\nimport dbt.exceptions\nimport agate\n\nfrom dbt.logger import GLOBAL_LOGGER as logger\n\n\nGET_RELATIONS_OPERATION_NAME = 'get_relations_data'\n\n\nclass PostgresAdapter(dbt.adapters.default.DefaultAdapter):\n\n    DEFAULT_TCP_KEEPALIVE = 0  # 0 means to use the default value\n\n    @contextmanager\n    def exception_handler(self, sql, model_name=None, connection_name=None):\n        try:\n            yield\n\n        except psycopg2.DatabaseError as e:\n            logger.debug('Postgres error: {}'.format(str(e)))\n\n            try:\n                # attempt to release the connection\n                self.release_connection(connection_name)\n            except psycopg2.Error:\n                logger.debug(\"Failed to release connection!\")\n                pass\n\n            raise dbt.exceptions.DatabaseException(\n                dbt.compat.to_string(e).strip())\n\n        except Exception as e:\n            logger.debug(\"Error running SQL: %s\", sql)\n            logger.debug(\"Rolling back transaction.\")\n            self.release_connection(connection_name)\n            raise dbt.exceptions.RuntimeException(e)\n\n    @classmethod\n    def type(cls):\n        return 'postgres'\n\n    @classmethod\n    def date_function(cls):\n        return 'datenow()'\n\n    @classmethod\n    def get_status(cls, cursor):\n        return cursor.statusmessage\n\n    @classmethod\n    def get_credentials(cls, credentials):\n        return credentials\n\n    @classmethod\n    def open_connection(cls, connection):\n        if connection.state == 'open':\n            logger.debug('Connection is already open, skipping open.')\n            return connection\n\n        base_credentials = connection.credentials\n        credentials = cls.get_credentials(connection.credentials.incorporate())\n        kwargs = {}\n        keepalives_idle = credentials.get('keepalives_idle',\n                                          cls.DEFAULT_TCP_KEEPALIVE)\n        # we don't want to pass 0 along to connect() as postgres will try to\n        # call an invalid setsockopt() call (contrary to the docs).\n        if keepalives_idle:\n            kwargs['keepalives_idle'] = keepalives_idle\n\n        try:\n            handle = psycopg2.connect(\n                dbname=credentials.dbname,\n                user=credentials.user,\n                host=credentials.host,\n                password=credentials.password,\n                port=credentials.port,\n                connect_timeout=10,\n                **kwargs)\n\n            connection.handle = handle\n            connection.state = 'open'\n        except psycopg2.Error as e:\n            logger.debug(\"Got an error when attempting to open a postgres \"\n                         \"connection: '{}'\"\n                         .format(e))\n\n            connection.handle = None\n            connection.state = 'fail'\n\n            raise dbt.exceptions.FailedToConnectException(str(e))\n\n        return connection\n\n    def cancel_connection(self, connection):\n        connection_name = connection.name\n        pid = connection.handle.get_backend_pid()\n\n        sql = \"select pg_terminate_backend({})\".format(pid)\n\n        logger.debug(\"Cancelling query '{}' ({})\".format(connection_name, pid))\n\n        _, cursor = self.add_query(sql, 'master')\n        res = cursor.fetchone()\n\n        logger.debug(\"Cancel query '{}': {}\".format(connection_name, res))\n\n    # DATABASE INSPECTION FUNCTIONS\n    # These require the profile AND project, as they need to know\n    # database-specific configs at the project level.\n    def alter_column_type(self, schema, table, column_name,\n                          new_column_type, model_name=None):\n        \"\"\"\n        1. Create a new column (w/ temp name and correct type)\n        2. Copy data over to it\n        3. Drop the existing column (cascade!)\n        4. Rename the new column to existing column\n        \"\"\"\n\n        relation = self.Relation.create(\n            schema=schema,\n            identifier=table,\n            quote_policy=self.config.quoting\n        )\n\n        opts = {\n            \"relation\": relation,\n            \"old_column\": column_name,\n            \"tmp_column\": \"{}__dbt_alter\".format(column_name),\n            \"dtype\": new_column_type\n        }\n\n        sql = \"\"\"\n        alter table {relation} add column \"{tmp_column}\" {dtype};\n        update {relation} set \"{tmp_column}\" = \"{old_column}\";\n        alter table {relation} drop column \"{old_column}\" cascade;\n        alter table {relation} rename column \"{tmp_column}\" to \"{old_column}\";\n        \"\"\".format(**opts).strip()  # noqa\n\n        connection, cursor = self.add_query(sql, model_name)\n\n        return connection, cursor\n\n    def _link_cached_relations(self, manifest, schemas):\n        try:\n            table = self.run_operation(manifest, GET_RELATIONS_OPERATION_NAME)\n        finally:\n            self.release_connection(GET_RELATIONS_OPERATION_NAME)\n        table = self._relations_filter_table(table, schemas)\n\n        for (refed_schema, refed_name, dep_schema, dep_name) in table:\n            referenced = self.Relation.create(schema=refed_schema,\n                                              identifier=refed_name)\n            dependent = self.Relation.create(schema=dep_schema,\n                                             identifier=dep_name)\n            self.cache.add_link(dependent, referenced)\n\n    def _list_relations(self, schema, model_name=None):\n        sql = \"\"\"\n        select tablename as name, schemaname as schema, 'table' as type from pg_tables\n        where schemaname ilike '{schema}'\n        union all\n        select viewname as name, schemaname as schema, 'view' as type from pg_views\n        where schemaname ilike '{schema}'\n        \"\"\".format(schema=schema).strip()  # noqa\n\n        connection, cursor = self.add_query(sql, model_name, auto_begin=False)\n\n        results = cursor.fetchall()\n\n        return [self.Relation.create(\n            database=self.config.credentials.dbname,\n            schema=_schema,\n            identifier=name,\n            quote_policy={\n                'schema': True,\n                'identifier': True\n            },\n            type=type)\n                for (name, _schema, type) in results]\n\n    def get_existing_schemas(self, model_name=None):\n        sql = \"select distinct nspname from pg_namespace\"\n\n        connection, cursor = self.add_query(sql, model_name, auto_begin=False)\n        results = cursor.fetchall()\n\n        return [row[0] for row in results]\n\n    def check_schema_exists(self, schema, model_name=None):\n        sql = \"\"\"\n        select count(*) from pg_namespace where nspname = '{schema}'\n        \"\"\".format(schema=schema).strip()  # noqa\n\n        connection, cursor = self.add_query(sql, model_name,\n                                            auto_begin=False)\n        results = cursor.fetchone()\n\n        return results[0] > 0\n\n    @classmethod\n    def convert_text_type(cls, agate_table, col_idx):\n        return \"text\"\n\n    @classmethod\n    def convert_number_type(cls, agate_table, col_idx):\n        decimals = agate_table.aggregate(agate.MaxPrecision(col_idx))\n        return \"float8\" if decimals else \"integer\"\n\n    @classmethod\n    def convert_boolean_type(cls, agate_table, col_idx):\n        return \"boolean\"\n\n    @classmethod\n    def convert_datetime_type(cls, agate_table, col_idx):\n        return \"timestamp without time zone\"\n\n    @classmethod\n    def convert_date_type(cls, agate_table, col_idx):\n        return \"date\"\n\n    @classmethod\n    def convert_time_type(cls, agate_table, col_idx):\n        return \"time\"\n", "path": "dbt/adapters/postgres/impl.py"}], "after_files": [{"content": "import psycopg2\n\nfrom contextlib import contextmanager\n\nimport dbt.adapters.default\nimport dbt.compat\nimport dbt.exceptions\nimport agate\n\nfrom dbt.logger import GLOBAL_LOGGER as logger\n\n\nGET_RELATIONS_OPERATION_NAME = 'get_relations_data'\n\n\nclass PostgresAdapter(dbt.adapters.default.DefaultAdapter):\n\n    DEFAULT_TCP_KEEPALIVE = 0  # 0 means to use the default value\n\n    @contextmanager\n    def exception_handler(self, sql, model_name=None, connection_name=None):\n        try:\n            yield\n\n        except psycopg2.DatabaseError as e:\n            logger.debug('Postgres error: {}'.format(str(e)))\n\n            try:\n                # attempt to release the connection\n                self.release_connection(connection_name)\n            except psycopg2.Error:\n                logger.debug(\"Failed to release connection!\")\n                pass\n\n            raise dbt.exceptions.DatabaseException(\n                dbt.compat.to_string(e).strip())\n\n        except Exception as e:\n            logger.debug(\"Error running SQL: %s\", sql)\n            logger.debug(\"Rolling back transaction.\")\n            self.release_connection(connection_name)\n            raise dbt.exceptions.RuntimeException(e)\n\n    @classmethod\n    def type(cls):\n        return 'postgres'\n\n    @classmethod\n    def date_function(cls):\n        return 'datenow()'\n\n    @classmethod\n    def get_status(cls, cursor):\n        return cursor.statusmessage\n\n    @classmethod\n    def get_credentials(cls, credentials):\n        return credentials\n\n    @classmethod\n    def open_connection(cls, connection):\n        if connection.state == 'open':\n            logger.debug('Connection is already open, skipping open.')\n            return connection\n\n        base_credentials = connection.credentials\n        credentials = cls.get_credentials(connection.credentials.incorporate())\n        kwargs = {}\n        keepalives_idle = credentials.get('keepalives_idle',\n                                          cls.DEFAULT_TCP_KEEPALIVE)\n        # we don't want to pass 0 along to connect() as postgres will try to\n        # call an invalid setsockopt() call (contrary to the docs).\n        if keepalives_idle:\n            kwargs['keepalives_idle'] = keepalives_idle\n\n        try:\n            handle = psycopg2.connect(\n                dbname=credentials.dbname,\n                user=credentials.user,\n                host=credentials.host,\n                password=credentials.password,\n                port=credentials.port,\n                connect_timeout=10,\n                **kwargs)\n\n            connection.handle = handle\n            connection.state = 'open'\n        except psycopg2.Error as e:\n            logger.debug(\"Got an error when attempting to open a postgres \"\n                         \"connection: '{}'\"\n                         .format(e))\n\n            connection.handle = None\n            connection.state = 'fail'\n\n            raise dbt.exceptions.FailedToConnectException(str(e))\n\n        return connection\n\n    def cancel_connection(self, connection):\n        connection_name = connection.name\n        pid = connection.handle.get_backend_pid()\n\n        sql = \"select pg_terminate_backend({})\".format(pid)\n\n        logger.debug(\"Cancelling query '{}' ({})\".format(connection_name, pid))\n\n        _, cursor = self.add_query(sql, 'master')\n        res = cursor.fetchone()\n\n        logger.debug(\"Cancel query '{}': {}\".format(connection_name, res))\n\n    # DATABASE INSPECTION FUNCTIONS\n    # These require the profile AND project, as they need to know\n    # database-specific configs at the project level.\n    def alter_column_type(self, schema, table, column_name,\n                          new_column_type, model_name=None):\n        \"\"\"\n        1. Create a new column (w/ temp name and correct type)\n        2. Copy data over to it\n        3. Drop the existing column (cascade!)\n        4. Rename the new column to existing column\n        \"\"\"\n\n        relation = self.Relation.create(\n            schema=schema,\n            identifier=table,\n            quote_policy=self.config.quoting\n        )\n\n        opts = {\n            \"relation\": relation,\n            \"old_column\": column_name,\n            \"tmp_column\": \"{}__dbt_alter\".format(column_name),\n            \"dtype\": new_column_type\n        }\n\n        sql = \"\"\"\n        alter table {relation} add column \"{tmp_column}\" {dtype};\n        update {relation} set \"{tmp_column}\" = \"{old_column}\";\n        alter table {relation} drop column \"{old_column}\" cascade;\n        alter table {relation} rename column \"{tmp_column}\" to \"{old_column}\";\n        \"\"\".format(**opts).strip()  # noqa\n\n        connection, cursor = self.add_query(sql, model_name)\n\n        return connection, cursor\n\n    def _link_cached_relations(self, manifest, schemas):\n        try:\n            table = self.run_operation(manifest, GET_RELATIONS_OPERATION_NAME)\n        finally:\n            self.release_connection(GET_RELATIONS_OPERATION_NAME)\n        table = self._relations_filter_table(table, schemas)\n\n        for (refed_schema, refed_name, dep_schema, dep_name) in table:\n            referenced = self.Relation.create(schema=refed_schema,\n                                              identifier=refed_name)\n            dependent = self.Relation.create(schema=dep_schema,\n                                             identifier=dep_name)\n\n            # don't record in cache if this relation isn't in a relevant schema\n            if refed_schema.lower() in schemas:\n                self.cache.add_link(dependent, referenced)\n\n    def _list_relations(self, schema, model_name=None):\n        sql = \"\"\"\n        select tablename as name, schemaname as schema, 'table' as type from pg_tables\n        where schemaname ilike '{schema}'\n        union all\n        select viewname as name, schemaname as schema, 'view' as type from pg_views\n        where schemaname ilike '{schema}'\n        \"\"\".format(schema=schema).strip()  # noqa\n\n        connection, cursor = self.add_query(sql, model_name, auto_begin=False)\n\n        results = cursor.fetchall()\n\n        return [self.Relation.create(\n            database=self.config.credentials.dbname,\n            schema=_schema,\n            identifier=name,\n            quote_policy={\n                'schema': True,\n                'identifier': True\n            },\n            type=type)\n                for (name, _schema, type) in results]\n\n    def get_existing_schemas(self, model_name=None):\n        sql = \"select distinct nspname from pg_namespace\"\n\n        connection, cursor = self.add_query(sql, model_name, auto_begin=False)\n        results = cursor.fetchall()\n\n        return [row[0] for row in results]\n\n    def check_schema_exists(self, schema, model_name=None):\n        sql = \"\"\"\n        select count(*) from pg_namespace where nspname = '{schema}'\n        \"\"\".format(schema=schema).strip()  # noqa\n\n        connection, cursor = self.add_query(sql, model_name,\n                                            auto_begin=False)\n        results = cursor.fetchone()\n\n        return results[0] > 0\n\n    @classmethod\n    def convert_text_type(cls, agate_table, col_idx):\n        return \"text\"\n\n    @classmethod\n    def convert_number_type(cls, agate_table, col_idx):\n        decimals = agate_table.aggregate(agate.MaxPrecision(col_idx))\n        return \"float8\" if decimals else \"integer\"\n\n    @classmethod\n    def convert_boolean_type(cls, agate_table, col_idx):\n        return \"boolean\"\n\n    @classmethod\n    def convert_datetime_type(cls, agate_table, col_idx):\n        return \"timestamp without time zone\"\n\n    @classmethod\n    def convert_date_type(cls, agate_table, col_idx):\n        return \"date\"\n\n    @classmethod\n    def convert_time_type(cls, agate_table, col_idx):\n        return \"time\"\n", "path": "dbt/adapters/postgres/impl.py"}]}