Add FILTER clause for aggregate functions in HQL #4007
Replies: 1 comment 1 reply
-
I'll consider the silence to be equal to agreement on adding support for this. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Copied over from https://trello.com/c/eyaZ8pcb/204-filter-clause-for-aggregate-functions
Support the SQL standard
FILTER
clause for aggregate functions in HQL. It can be emulated by doing<<aggregate_function>>(case when <<filter_predicate>> then <<argument>> else null end)
because all aggregate functions are null rejecting.Here some examples:
SUM(tx.amount) FILTER (WHERE tx.category = 'work')
can be emulated asSUM(CASE WHEN tx.category = 'work' THEN tx.amount ELSE NULL END)
COUNT(*) FILTER (WHERE alias.isActive = true)
can be emulated asCOUNT(CASE WHEN alias.isActive = true THEN 1 ELSE NULL END)
I needed to add discriminate normal functions from aggregate functions for the lock handling and I introduced as part of that PR the filter predicate on aggregate functions, but I wanted to get everyone's opinion first before also adding the HQL syntax for this.
Beta Was this translation helpful? Give feedback.
All reactions