dbt-labs / dbt-labs/dbt-adapters

sync_all_columns drops all columns when datasharing: true on Redshift

Open
#1,991 1 comment 0 reactions 0 assignees View on GitHub
triage:product type:bug
Dominant language
Python
Stars
233
Forks
362
Avg merge
3d 22h
Merged PRs (30d)
9

Description

### Is this a new bug?

- [x] I believe this is a new bug
- [x] I have searched the existing issues, and I could not find an existing issue for this bug

### Which packages are affected?

- [x] dbt-adapters
- [ ] dbt-tests-adapter
- [ ] dbt-athena
- [ ] dbt-athena-community
- [ ] dbt-bigquery
- [ ] dbt-postgres
- [x] dbt-redshift
- [ ] dbt-snowflake
- [ ] dbt-spark

### Current Behavior

When a Redshift connection is configured with `datasharing: true`, `information_schema.columns` returns zero rows when queried against a session-local temp table (e.g. __dbt_tmp). The query executes successfully with no error — it simply returns no rows.
With on_schema_change='sync_all_columns', dbt interprets this as "source has 0 columns, target has all N columns" and issues `ALTER TABLE ... DROP COLUMN` for every column in the target table. All drops succeed at the Redshift layer. The subsequent DELETE then fails immediately because the unique key columns were just dropped:
`Redshift error: column "" does not exist in `

### Expected Behavior

`sync_all_columns` should correctly resolve the schema of the temp table when `datasharing: true` is configured, and should not drop columns that exist in the source.

### Steps To Reproduce

Steps To Reproduce

1. Configure a Redshift connection with datasharing: true
2. Create an incremental model with on_schema_change='sync_all_columns' and one or more unique_key columns
3. Run the model incrementally
4. Observe that information_schema.columns returns 0 rows for the temp table, all target columns are dropped, and the DELETE fails

### Relevant log output

```shell
-- Step 1: information_schema.columns on the temp table — succeeds but returns 0 rows
with bound_views as (
select ordinal_position, table_schema, column_name, data_type, ...
from information_schema."columns"
where table_name = '__dbt_tmp'
)
...
-- SQL status: SUCCESS (~55 seconds, 0 rows returned)

-- Step 2: sync_all_columns diff
Schema changed: True
Source columns not in target: []
Target columns not in source: [col1, col2, ..., , ...] -- all N columns

-- Step 3: dbt drops all columns
alter table "".""."" drop column "col1" -- SUCCESS
alter table "".""."" drop column "col2" -- SUCCESS
-- ... N more DROP COLUMNs ...

-- Step 4: DELETE fails
delete from ""."".""
where () in (
select distinct
from "__dbt_tmp" as DBT_INTERNAL_SOURCE
);
-- Redshift error: column "" does not exist in
```

### Environment

```markdown
- OS:
- Python:
- dbt-adapters:
- :
```

### Additional Context

related slack thread: https://dbt-labs.slack.com/archives/C067EUS2D7S/p1780038445793949

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.