New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pivot with IN clause doesn't work for a boolean column #8596
Comments
This comment was marked as abuse.
This comment was marked as abuse.
I wondered if it was all uses of IN with boolean, but |
You could also employ your IN as a values list, e.g.:
Results:
This also works, it assumes the result:
Rule of thumb I like to use when reading error messages is the hint, list must contain columns... oh, yah, an array isn't column(s), hence "values" addresses the issue. Hope this helped. |
Thanks for the suggestion. This works too: |
Still repros in 0.9.0 |
Fix #8596 - use ConstructConstantFromExpression for PIVOT IN list
What happens?
You can use an IN clause to specify the values to make into columns. If you do this with a boolean expression, you get a strange error:
Error: Parser Error: PIVOT IN list must contain columns or lists of columns
This is a somewhat odd thing to want to do, but the IN clause does tell the database that columns should be created for both values. Otherwise, columns are created only for the values present.
To Reproduce
Run the following SQL:
-- Example data from documentation for PIVOT
CREATE TABLE Cities(Country VARCHAR, Name VARCHAR, Year INT, Population INT);
INSERT INTO Cities VALUES ('NL', 'Amsterdam', 2000, 1005);
INSERT INTO Cities VALUES ('NL', 'Amsterdam', 2010, 1065);
INSERT INTO Cities VALUES ('NL', 'Amsterdam', 2020, 1158);
INSERT INTO Cities VALUES ('US', 'Seattle', 2000, 564);
INSERT INTO Cities VALUES ('US', 'Seattle', 2010, 608);
INSERT INTO Cities VALUES ('US', 'Seattle', 2020, 738);
INSERT INTO Cities VALUES ('US', 'New York City', 2000, 8015);
INSERT INTO Cities VALUES ('US', 'New York City', 2010, 8175);
INSERT INTO Cities VALUES ('US', 'New York City', 2020, 8772);
-- PIVOT on string column with IN clause works
pivot cities on Country in ('NL','US') using avg(Population) group by name;
-- PIVOT on boolean expression without IN clause works
pivot cities on (Country='NL') using avg(Population) group by name;
-- PIVOT on boolean expression with IN clause does not work
pivot cities on (Country='NL') in (false, true) using avg(Population) group by name;
OS:
Windows amd64
DuckDB Version:
0.8.2 main
DuckDB Client:
CLI
Full Name:
Dan Cory
Affiliation:
self
Have you tried this on the latest
master
branch?I have tested with a master build
Have you tried the steps to reproduce? Do they include all relevant data and configuration? Does the issue you report still appear there?
The text was updated successfully, but these errors were encountered: