dbt-labs / dbt-labs/dbt

[BUG] Redshift: aliasing in `unpivot` not supported

Open
#14,122 0 comments 0 reactions 0 assignees View on GitHub
adapter:redshift area:static-analysis engine:v2 status:needs-repro status:triage type:bug
Dominant language
Rust
Stars
13.8k
Forks
2.6k
Avg merge
21h 31m
Merged PRs (30d)
56

Description

**Describe the bug**
When using the `unpivot` operator in a CTE with an `in` list of values, Fusion will return the following error if those values are aliased:
`error: dbt0101: mismatched input 'as' expecting one of ',', ')'`

The below example model demonstrates this behavior. It will build without issue in dbt Core.

**What version of dbt Fusion is this bug in? (find out by running `dbt --version`)**
dbt-fusion 2.0.0-preview.92

**Is this a discrepancy between the dbt Fusion Engine and dbt Core? Check one.**
- [x] YES
- [ ] NO

**To Reproduce**
Example model:
```
{{ config(
materialized = 'table'
) }}

with count_by_color as (
select 'high' as quality, 15 as red, 20 as green, 7 as blue
union all
select 'normal' as quality, 35 as red, NULL as green, 40 as blue
union all
select 'low' as quality, 10 as red, 23 as green, NULL as blue
),

unpivot_colors as (
select *
from count_by_color
unpivot (
col_count for color in (
red as r,
green as g,
blue as b
)
)
)

select * from unpivot_colors
```

**Expected behavior**
The dbt build command should cause the model to successfully run and output the following table:

| quality | color | col_count |
|---------|-------|-----------|
| normal | r | 35 |
| normal | b | 40 |
| high | r | 15 |
| low | r | 10 |
| high | g | 20 |
| low | g | 23 |
| high | b | 7 |

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Operating System and CPU Type:**
* Windows
* x64

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.