question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Generated HQL for a Count Query with multiple Group By columns not producing valid SQL for MSSQL

See original GitHub issue

Related 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:

https://hibernate.atlassian.net/browse/HHH-11042?page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel&showAll=true

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:closed
  • Created 6 years ago
  • Reactions:6
  • Comments:7

github_iconTop GitHub Comments

2reactions
syedammarziacommented, Oct 21, 2019

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.

0reactions
stale[bot]commented, Jun 3, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found