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

JSqlParserQueryEnhancer produces invalid query that JSqlParser can't parse #3707

Closed
edudar-chwy opened this issue Dec 8, 2024 · 1 comment
Assignees
Labels
type: bug A general bug

Comments

@edudar-chwy
Copy link

While trying all options to solve an issue mentioned in #3706, I tried JSqlParser. It created a count query closer to what it should be—it understands DISTINCT, at least. However, the enhancer created an invalid query.

Original query:

SELECT DISTINCT a.*, b.b1
FROM TableA a
  JOIN TableB b ON ...
  LEFT JOIN TableC ON ...
WHERE ...
ORDER BY b.b1, a.a1, a.a2

Derived count query:

SELECT count(DISTINCT *)
FROM TableA a
  JOIN TableB b ON ...
  LEFT JOIN TableC ON ...
WHERE ...

The enhancer complains that The query you provided is not a valid SQL Query and that it Encountered unexpected token: "(" "(" at line 1, column 13. The DB (Postgres) also fails this query because it should say SELECT count(DISTINCT a.*) FROM ....

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Dec 8, 2024
@mp911de mp911de self-assigned this Dec 9, 2024
@mp911de mp911de added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Dec 10, 2024
mp911de added a commit that referenced this issue Dec 10, 2024
…queries.

We now use render COUNT(DISTINCT a.*) where 'a' is the primary table alias instead of COUNT(DISTINCT *).

Closes #3707
mp911de added a commit that referenced this issue Dec 10, 2024
…queries.

We now use render COUNT(DISTINCT a.*) where 'a' is the primary table alias instead of COUNT(DISTINCT *).

Closes #3707
@mp911de mp911de added this to the 3.3.7 (2024.0.7) milestone Dec 10, 2024
@mp911de
Copy link
Member

mp911de commented Dec 10, 2024

That's fixed now and available from the latest snapshots at repo.spring.io. We prepend the primary table alias to * in the context of COUNT(DISTINCT *)).

Care to give the fix a try?

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

No branches or pull requests

3 participants