Schema tests raise SQL error when columns contain space
See original GitHub issueHi,
Schema tests on columns that contain spaces are currently raising a SQL error. This is due to the macro generating the following SQL code
select count(*) as validation_errors
from "DB"."schema"."table"
where My Column Name is null
I tried to change the column name in schema.yml
to put it in the format "'My Column Name'"
, but while the schema test now works, the documentation shows 2 different entries for my column, one with My Column Name
and one with 'My Column Name'
(including the single quotes).
I also tried to replace My Column Name
with [My Column Name]
but I get the same result, the test is working but I am getting a duplicate column in the documentation.
I think that wrapping the column name in single quotes in the macros defined in schema_tests.sql would prevent this problem. So, replacing {% set column_name = kwargs.get('column_name', kwargs.get('arg')) %}
by {% set column_name = "'" ~ kwargs.get('column_name', kwargs.get('arg')) ~ "'" %}
Does it sound ok? If so, I am happy to create a Pull Request with those changes.
Issue Analytics
- State:
- Created 3 years ago
- Comments:7
I just realised that since v0.16 dbt allows for quote configuration to be set up at the column level: https://docs.getdbt.com/reference/resource-properties/quote/
Once dbt-sqlserver is ready for v0.18 I’ll come back to this one and see how this parameter can potentially fix this issue and if some code change is required in the macros.
I just tried to use the
quote
column property along with #46 and the tests work fine, even with columns with spaces. So I will close this one and there is no need to updateschema_tests.sql
.