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

_sort=near throws exception when used in offset search #6709

Open
patrick-werner opened this issue Feb 13, 2025 · 0 comments · May be fixed by #6710
Open

_sort=near throws exception when used in offset search #6709

patrick-werner opened this issue Feb 13, 2025 · 0 comments · May be fixed by #6710

Comments

@patrick-werner
Copy link
Member

patrick-werner commented Feb 13, 2025

Describe the bug
When using a near search WITH _sort=near and WITH offset search a SQLGrammarException is thrown. This is caused by a bug in the SearchQueryBuilder of the com.healthmarketscience.sqlbuilder package.

To Reproduce
Steps to reproduce the behavior:
Start a hapi(jpastarter) server and search: http://localhost:8080/fhir/Location?near=50.097%7C8.6648%7C1000&_sort=near&_count=1&_offset=1

"HAPI-1262: org.hibernate.exception.SQLGrammarException: JDBC exception executing SQL [SELECT t1.RES_ID,(ABS((t0.SP_LATITUDE - ?)) + ABS((t0.SP_LONGITUDE - ?))) AS MHD0 FROM HFJ_RESOURCE t1 INNER JOIN HFJ_SPIDX_COORDS t0 ON (t1.RES_ID = t0.RES_ID) WHERE ((t0.HASH_IDENTITY = ?) AND (((t0.SP_LATITUDE >= ?) AND (t0.SP_LATITUDE <= ?)) AND ((t0.SP_LONGITUDE >= ?) AND (t0.SP_LONGITUDE <= ?)))) GROUP BY t1.RES_ID ORDER BY MHD0 offset ? rows fetch next ? rows only] [ERROR: column \"t0.sp_latitude\" must appear in the GROUP BY clause or be used in an aggregate function\n Position: 24] [n/a]"

Expected behavior
All resources are returned in the correct order, no exception is thrown.

Actual behaviour
PostgreSQL rejects the query because t0.SP_LATITUDE and t0.SP_LONGITUDE are neither included in the GROUP BY clause nor used in an aggregate function.

Environment (please complete the following information):

  • HAPI FHIR 7.6.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant