Generated HQL for a Count Query with multiple Group By columns not producing valid SQL for MSSQL
See original GitHub issueRelated to #1472
I think the fix introduced a bug. When I do aggregations on any column and add a new group by. It will generate a count query HQL that looks like this:
select count(distinct col1, col2)
// where col1 and col2 are the group by columns.
In MSSQL it will throw an exception as the generated SQL from the HQL is not valid SQL for MSSQL.
The issue has been touched on this hibernate issue:
With the result being to implement a dialect specific sql function for sql server that would create valid sql for this use case. The resulting sql would have the following format:
count(distinct coalesce(nullif(coalesce(col1 || '', '\0'), ''), '\01') || '\0' || coalesce(nullif(coalesce(col2 || '', '\0'), ''), '\02'))
Is there any way to do this right now in querydsl (i.e. add your own override count function to the count query)? What do you guys think a good workaround would be?
Thanks,
Gary
Issue Analytics
- State:
- Created 6 years ago
- Reactions:6
- Comments:7
Top Results From Across the Web
sql - COUNT DISTINCT with CONDITIONS - Stack Overflow
I'm now counting from two different tables where in the second table I've only selected those rows with entryID larger than zero. I...
Read more >SQL GROUP BY clause - w3resource
The GROUP BY clause is used with the SELECT statement to make a group of rows based on the values of a specific...
Read more >NULL Values and the GROUP BY Clause - LearnSQL.com
This empty space represents all the NULL values returned by the GROUP BY clause, so we can conclude that GROUP BY treats NULLs...
Read more >Chapter 15. HQL: The Hibernate Query Language
A query that returns aggregate values can be grouped by any property of a returned class or components: · A having clause is...
Read more >Why do we use Group by 1 and Group by 1,2,3 in SQL query?
it's not self-documenting - someone is going to have to go parse the SELECT list to figure out the grouping. It would actually...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Facing this issue. It is a pretty basic issue and should be fixed. Is there any timeline for this? It seems like it is already long overdue.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.