Skip to content

Commit 24af1ca

Browse files
authored
Merge pull request #677 from Benjamin-Knight/fix/#619-reserved-keyword-schema-quoting
Fix reserved-keyword quoting in table-create DROP VIEW (#619).
2 parents b2f30ca + c1a4faa commit 24af1ca

2 files changed

Lines changed: 56 additions & 1 deletion

File tree

dbt/include/sqlserver/macros/relations/table/create.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
EXEC('{{- escape_single_quotes(query) -}}')
3434

3535
{# For some reason drop_relation is not firing. This solves the issue for now. #}
36-
EXEC('DROP VIEW IF EXISTS {{tmp_relation.schema}}.{{tmp_relation.identifier}}')
36+
EXEC('DROP VIEW IF EXISTS {{ tmp_relation.include(database=False) }}')
3737

3838

3939

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import pytest
2+
3+
from dbt.tests.util import run_dbt
4+
5+
model_sql = """
6+
{{ config(materialized="table") }}
7+
select 1 as id
8+
"""
9+
10+
11+
class TestReservedKeywordsSchema:
12+
@pytest.fixture(scope="class")
13+
def models(self):
14+
return {"model.sql": model_sql}
15+
16+
@pytest.fixture(scope="class")
17+
def project_config_update(self):
18+
return {
19+
"name": "test_reserved_keywords_schema",
20+
"quoting": {
21+
"database": True,
22+
"schema": True,
23+
"identifier": True,
24+
},
25+
"models": {
26+
"test_reserved_keywords_schema": {
27+
"schema": "group",
28+
}
29+
},
30+
}
31+
32+
@pytest.fixture(scope="class")
33+
def macros(self):
34+
return {
35+
"generate_schema_name.sql": """
36+
{% macro generate_schema_name(custom_schema_name, node) -%}
37+
{%- if custom_schema_name -%}
38+
{{ custom_schema_name | trim }}
39+
{%- else -%}
40+
{{ target.schema }}
41+
{%- endif -%}
42+
{%- endmacro %}
43+
"""
44+
}
45+
46+
@pytest.fixture(autouse=True, scope="class")
47+
def cleanup_schema(self, project):
48+
yield
49+
project.run_sql("DROP TABLE IF EXISTS [group].[model]")
50+
project.run_sql("DROP SCHEMA IF EXISTS [group]")
51+
52+
def test_reserved_schema(self, project):
53+
results = run_dbt(["run"])
54+
assert len(results) == 1
55+
assert results[0].status == "success"

0 commit comments

Comments
 (0)