question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Schema tests raise SQL error when columns contain space

See original GitHub issue

Hi,

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:closed
  • Created 3 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
b-percommented, Aug 22, 2020

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.

0reactions
b-percommented, Aug 29, 2020

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 update schema_tests.sql.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Schema tests raise SQL error when columns contain space #37
Hi, Schema tests on columns that contain spaces are currently raising a SQL error. This is due to the macro generating the following...
Read more >
Error when querying a SQL Server view with whitespace in the ...
I'm using Powershell to test queries on certain SQL Server tables and views, one of which has whitespace in its name. The schema...
Read more >
How to write SQL queries with spaces in column names
Suppose we want to create a table named tblCountries. The table has two columns named country code and country name. Following is the...
Read more >
Database Engine events and errors - SQL Server
Consult this MSSQL error code list to find explanations for error messages for SQL Server database engine events.
Read more >
Error Creating Space: Invalid column name 'true'. | Confluence
This is due to an error in the initial database configuration. If the database was set up incorrectly, Confluence cannot created the data ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found