Skip to content
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

bug: pivot query can not support subquery #16556

Open
1 of 2 tasks
cdmikechen opened this issue Oct 1, 2024 · 2 comments
Open
1 of 2 tasks

bug: pivot query can not support subquery #16556

cdmikechen opened this issue Oct 1, 2024 · 2 comments
Labels
A-query Area: databend query C-bug Category: something isn't working

Comments

@cdmikechen
Copy link

Search before asking

  • I had searched in the issues and found no similar issues.

Version

v1.2.615

What's Wrong?

pivot does not support subquery

How to Reproduce?

referenced document: https://docs.databend.com/sql/sql-commands/query-syntax/query-pivot

error sql:

SELECT * 
FROM (select * from monthly_sales)
PIVOT(SUM(amount) FOR MONTH IN (select distinct month from monthly_sales))
ORDER BY EMPID;

If I use a view, databend can support subquey in from:

create view v_monthly_sales as select * from monthly_sales;
 
SELECT * 
FROM v_monthly_sales
PIVOT(SUM(amount) FOR MONTH IN ('JAN', 'FEB', 'MAR', 'APR'))
ORDER BY EMPID;

Assuming all months are in the results and need to be used, how can I do the query correctly without writing a for?

Are you willing to submit PR?

  • Yes I am willing to submit a PR!
@cdmikechen cdmikechen added the C-bug Category: something isn't working label Oct 1, 2024
@sundy-li
Copy link
Member

sundy-li commented Oct 5, 2024

pivot doesn't support subquery now.

let pivot = map(
        rule! {
           PIVOT ~ "(" ~ #expr ~ FOR ~ #ident ~ IN ~ "(" ~ #comma_separated_list1(expr) ~ ")" ~ ")"
        },
        |(_pivot, _, aggregate, _for, value_column, _in, _, values, _, _)| Pivot {
            aggregate,
            value_column,
            values,
        },
    );

@sundy-li sundy-li added the A-query Area: databend query label Oct 5, 2024
@cdmikechen
Copy link
Author

@sundy-li
If databend have supported from or in statements with pivot, then normal people use the habit of writing regular sql with subquery.
Without supporting it, I think the usability of this feature is really low. In fact, a lot of data processing is based on the data dynamic execution. Or to put it another way, will this subquery be considered for support in the future?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-query Area: databend query C-bug Category: something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants