Skip to content

Conversation

@Mytherin
Copy link
Collaborator

This PR improves the error messages when using UNPIVOT, e.g.:

D UNPIVOT (select 42 as col1, 'woot' as col2)
          on col1, col2;
Error: Binder Error: Cannot unpivot columns of types INTEGER and VARCHAR - an explicit cast is required
Full list: col1 INTEGER, col2 VARCHAR
                         ^

Previously we did not mention "unpivot" which made the error message confusing.

In addition, we allow expressions within the UNPIVOT statements, provided they only involve a single column, e.g.:

D unpivot (select 42 as col1, 'woot' as col2)
          on col1::VARCHAR, col2;
┌─────────┬─────────┐
│  name   │  value  │
│ varcharvarchar │
├─────────┼─────────┤
│ col1    │ 42      │
│ col2    │ woot    │
└─────────┴─────────┘

This is not allowed still:

D unpivot (select 42 as col1, 'woot' as col2)
          on col1+col2;
Error: Binder Error: UNPIVOT clause must contain exactly one column - expression "(col1 + col2)" contains multiple (col1, col2)
LINE 2:         on col1+col2;
                       ^

We now also always keep the original aliases of the column if none are specified - e.g.:

D unpivot (select 42 as col1, 'woot' as col2)
          on columns(*)::VARCHAR;
┌─────────┬─────────┐
│  name   │  value  │
│ varcharvarchar │
├─────────┼─────────┤
│ col1    │ 42      │
│ col2    │ woot    │
└─────────┴─────────┘

@Alex-Monahan
Copy link
Contributor

Wow, this is perfect! All cases are handled really nicely. Thank you!!

github-actions bot pushed a commit to duckdb/duckdb-r that referenced this pull request Mar 15, 2024
Merge pull request duckdb/duckdb#10773 from Mytherin/unpivoterror
Merge pull request duckdb/duckdb#10763 from Tmonster/add-large-benchmarks
@Mytherin Mytherin deleted the unpivoterror branch July 5, 2024 11:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Friendly SQL Needs Documentation Use for issues or PRs that require changes in the documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants