dbt-labs / dbt-labs/dbt-adapters
[Bug] Incremental compilation error alter queries not using quoted columns
- Dominant language
- Python
- Stars
- 233
- Forks
- 362
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 9
Description
### Is there an existing issue for this?
- [X] I have searched the existing issues
### Current Behavior
I've created a repository with multiple tests that summarizes compilation errors with SQL queries generated by dbt when running incremental models at: https://github.com/airbytehq/testing_dbt
One of the issues occurs when we rename columns of an incremental model (with on_schema_change: sync_all_columns) while including special characters in the new column name. Therefore the columns should be referred to with quoting.
from https://github.com/airbytehq/testing_dbt/blob/2d8f87b721e13122dd5fd9fa8088ee7734f9017e/first_project/models/change_column_names.sql
renamed to https://github.com/airbytehq/testing_dbt/blob/2d8f87b721e13122dd5fd9fa8088ee7734f9017e/second_project/models/change_column_names.sql
- Table creation works properly while quoting identifiers.
```
create temporary table "change_column_names__dbt_tmp204510736609"
as (
select
'replacing underscore with space' as "new column name"
now() as insert_time
);
```
https://github.com/airbytehq/testing_dbt/blob/2d8f87b721e13122dd5fd9fa8088ee7734f9017e/output/postgres-3-schema-change-FAILED-dbt.log#L279
- But `alter table` queries fails when using incremental materialization:
```
alter table "postgres"."tests"."change_column_names"
add column new column name text,
drop column column_name,
```
https://github.com/airbytehq/testing_dbt/blob/2d8f87b721e13122dd5fd9fa8088ee7734f9017e/output/postgres-3-schema-change-FAILED-dbt.log#L1555
### Expected Behavior
The expected SQL query should be:
```
alter table "postgres"."tests"."change_column_names"
add column "new column name" text,
drop column column_name,
```
### Steps To Reproduce
1. in https://github.com/airbytehq/testing_dbt/
2. ./run_test.sh
### Relevant log output
_No response_
### Environment
```markdown
- OS: mac Os & docker (fishtownanalytics/dbt)
- Python: 3.8.12
- dbt: 0.21.0
```
### What database are you using dbt with?
postgres, redshift, snowflake, other (mention it in "Additional Context")
### Additional Context
The error occurs with:
- postgres
- redshift
- snowflake
- sqlserver
Contributor guide
Assessment
This issue has not been assessed yet.