dbt-labs / dbt-labs/dbt-adapters

[Bug] Snapshots and incremental models cannot add array columns

Open
#664 4 comments 1 reaction 0 assignees View on GitHub
feature:incremental feature:snapshots pkg:dbt-postgres 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

### Current Behavior

Adding an array-type column to an existing snapshot or incremental model will result in the following [syntax error](https://stackoverflow.com/questions/26932978/trying-to-add-an-array-column-to-existing-postgres-table).

`alter table "postgres"."dbt_teddy_snapshots"."test_model_snapshot" add column "some_array" ARRAY;`
`Postgres adapter: Postgres error: syntax error at or near "ARRAY"`

**Example**
```
# example_model.sql (before)
select
1::numeric as col_a,
2::int as col_b,
'some_text' as col_c

# example_model.sql (after)
select
1::numeric as col_a,
2::int as col_b,
'some_text' as col_c
null::text[] as some_array
```

### Expected Behavior

Alter table command should look like something like the following:
`alter table "postgres"."dbt_snapshots"."example_model_snapshot" add column "some_array" text[];`

### Steps To Reproduce

1. Build above `example_model` with a downstream snapshot and incremental model
2. Add an array column to `example_model`
3. Build `example_model` and the downstream incremental models and snapshots

### Relevant log output

```shell
14:41:28.002733 [debug] [Thread-1 (]: SQL status: SELECT 8 in 0.003 seconds
14:41:28.005418 [debug] [Thread-1 (]: Using postgres connection "snapshot.thymecare.test_model_snapshot"
14:41:28.005658 [debug] [Thread-1 (]: On snapshot.thymecare.test_model_snapshot: /* {"app": "dbt", "dbt_version": "1.8.6", "profile_name": "postgres", "target_name": "local", "node_id": "snapshot.thymecare.test_model_snapshot"} */

alter table "postgres"."dbt_snapshots"."test_model_snapshot" add column "some_array" ARRAY;

14:41:28.009511 [debug] [Thread-1 (]: Postgres adapter: Postgres error: syntax error at or near "ARRAY"
LINE 3: ...pshots"."test_model_snapshot" add column "some_array" ARRAY;
```

### Environment

```markdown
- OS: Sequoia 15.0.1
- Python: 3.11.4
- dbt-postgres: 1.8.2
```

### Additional Context

_No response_

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.