Skip to content

QueryUtils derive broken count query when original one contains ORDER BY with new lines #3329

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

Closed
edudar opened this issue Jan 23, 2024 · 2 comments
Assignees
Labels
type: bug A general bug

Comments

@edudar
Copy link
Contributor

edudar commented Jan 23, 2024

Stumbled upon this issue while moving SQL queries to text blocks. Consider the following:

"""
SELECT * FROM table t
WHERE t.id = :id
  AND t.deleted = FALSE
ORDER BY t.active DESC,
         t.creation_date DESC
"""

Such a query will fail to run because Spring Data tries to derive a count query from this one and removes the ORDER BY part, but only when it's in a single line

QueryUtils.ORDER_BY_PART = "(?iu)\\s+order\\s+by\\s+.*";

If it's multi-line text, the count query turns like

select count(1) FROM table t
WHERE t.id = :id
AND t.deleted = FALSE
t.creation_date DESC

and expectedly fails.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jan 23, 2024
@edudar
Copy link
Contributor Author

edudar commented Jan 23, 2024

This relates to #1813 but goes even further.

@christophstrobl
Copy link
Member

Thank for @edudar for raising the issue and creating the PR. We'll have a look.

@christophstrobl christophstrobl added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Jan 29, 2024
@christophstrobl christophstrobl self-assigned this Jan 29, 2024
christophstrobl pushed a commit that referenced this issue Feb 1, 2024
christophstrobl pushed a commit that referenced this issue Feb 1, 2024
@christophstrobl christophstrobl added this to the 3.1.9 (2023.0.9) milestone Feb 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants