awslabs / awslabs/amazon-redshift-utils
sp_pivot_for needs to handle empty sets gracefully
- Dominant language
- Python
- Stars
- 2.8k
- Forks
- 1.2k
- PR merge metrics
- No merged PRs in 30d
Description
sp_pivot_for will run into an issue with the dynamic sql when it tries to pivot and there are no rows in the pivot table.
To reproduce this you can run one of the example CALLs in the SP but truncate the table ahead of time.
A solution could just be to run a quick count(*) on the source table and return an error if the value = 0
Contributor guide
Research direction
Locate the sp_pivot_for stored procedure and its example CALLs, then reproduce the failure with the pivot table truncated. Trace how dynamic SQL is generated for an empty source and verify that the procedure handles the no-row case with a clear result or error instead of failing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- sql
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100