Skip to content

Commit 320a250

Browse files
fix: add BigQuery backtick escaping for database identifiers (CodeRabbit suggestion)
Co-Authored-By: Itamar Hartstein <haritamar@gmail.com>
1 parent 45c65ef commit 320a250

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

integration_tests/dbt_project/macros/schema_utils/list_schemas.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
{% endmacro %}
2222
2323
{% macro bigquery__edr_list_schemas(database) %}
24-
{% set results = run_query("SELECT schema_name FROM `" ~ database ~ "`.INFORMATION_SCHEMA.SCHEMATA") %}
24+
{% set safe_db = database | replace("`", "\`") %}
25+
{% set results = run_query("SELECT schema_name FROM `" ~ safe_db ~ "`.INFORMATION_SCHEMA.SCHEMATA") %}
2526
{% set schemas = [] %}
2627
{% for row in results %}
2728
{% do schemas.append(row[0]) %}

integration_tests/dbt_project/macros/schema_utils/schema_exists.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
{% endmacro %}
1919
2020
{% macro bigquery__edr_schema_exists(database, schema_name) %}
21+
{% set safe_db = database | replace("`", "\`") %}
2122
{% set safe_schema = schema_name | replace("'", "''") %}
22-
{% set result = run_query("SELECT schema_name FROM `" ~ database ~ "`.INFORMATION_SCHEMA.SCHEMATA WHERE lower(schema_name) = lower('" ~ safe_schema ~ "')") %}
23+
{% set result = run_query("SELECT schema_name FROM `" ~ safe_db ~ "`.INFORMATION_SCHEMA.SCHEMATA WHERE lower(schema_name) = lower('" ~ safe_schema ~ "')") %}
2324
{% do return(result | length > 0) %}
2425
{% endmacro %}
2526

0 commit comments

Comments
 (0)