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

Fix(snowflake): use IF instead of FILTER(WHERE cond) for conditional aggregation #2241

Merged
merged 2 commits into from
Sep 17, 2023

Conversation

georgesittas
Copy link
Collaborator

Fixes #2239

sqlglot/generator.py Outdated Show resolved Hide resolved
@georgesittas georgesittas changed the title Fix(snowflake): use CASE instead of FILTER(WHERE cond) for conditional aggregation Fix(snowflake): use IF instead of FILTER(WHERE cond) for conditional aggregation Sep 16, 2023
@georgesittas georgesittas merged commit 12de208 into main Sep 17, 2023
@georgesittas georgesittas deleted the jo/filter_where_fix branch September 17, 2023 01:06
agg = expression.this.copy()
agg_arg = agg.this
cond = expression.expression.this
agg_arg.replace(exp.If(this=cond.copy(), true=agg_arg.copy(), false=exp.null()))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the false is unnecessary it’s implied null

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed this in d5ad990

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

aggregate filter compiles to invalid syntax for some dialects
2 participants