From d1a73b0be3b01098a324d27ed71361487c98f5ee Mon Sep 17 00:00:00 2001
From: Pieter Ennes <pieter@ennes.nl>
Date: Tue, 28 May 2024 21:06:37 +0200
Subject: [PATCH 1/2] Fix unquoted database name

---
 macros/sql/get_tables_by_pattern_sql.sql | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/macros/sql/get_tables_by_pattern_sql.sql b/macros/sql/get_tables_by_pattern_sql.sql
index 03f96624..62466456 100644
--- a/macros/sql/get_tables_by_pattern_sql.sql
+++ b/macros/sql/get_tables_by_pattern_sql.sql
@@ -9,7 +9,7 @@
             table_schema as {{ adapter.quote('table_schema') }},
             table_name as {{ adapter.quote('table_name') }},
             {{ dbt_utils.get_table_types_sql() }}
-        from {{ database }}.information_schema.tables
+        from {{ adapter.quote(database) }}.information_schema.tables
         where table_schema ilike '{{ schema_pattern }}'
         and table_name ilike '{{ table_pattern }}'
         and table_name not ilike '{{ exclude }}'

From c998f1bdbea92cc67565f8c8d07f2e62ae0838cb Mon Sep 17 00:00:00 2001
From: Pieter Ennes <pieter@ennes.nl>
Date: Tue, 28 May 2024 19:23:53 +0000
Subject: [PATCH 2/2] Add changelog entry

---
 CHANGELOG.md | 1 +
 1 file changed, 1 insertion(+)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4b63af45..e92bf57f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -19,6 +19,7 @@
 - get_tables_by_pattern_sql will now:
   - return redshift external tables ([#752](https://github.com/dbt-labs/dbt-utils/issues/752)
   - work with valid redshift database names that contain dashes
+- fix quoting of database names when using get_relations_by_prefix() [#899](https://github.com/dbt-labs/dbt-utils/pull/899)
 ## Under the hood
 - created a new dispatch redshift__get_tables_by_pattern which unions the result of the default macro and querying svv_external_tables for the same conditions (schema name, pattern, exclude pattern).