spring-data-jpa icon indicating copy to clipboard operation
spring-data-jpa copied to clipboard

`QueryUtils` does not detect alias of MERGE in native queries

Open DiegoKrupitza opened this issue 3 years ago • 2 comments

As discovered in #2642 QueryUtils does not correctly detect the alias which is used in a merge statement. Hence the following test case fails:

@Test 
void queryUtilsDetectsMergeAliasCorrectly() {
        String alias = QueryUtils.detectAlias(
		"merge into a using (select id, value from b) query on (a.id = query.id) when matched then update set a.value = value");

        assertThat(alias).isNotNull().isNotEmpty();
}

The test case fails because detectAlias(...) returns NULL instead of query.

DiegoKrupitza avatar Sep 28 '22 10:09 DiegoKrupitza

We are working on a parsing solution to better handle such situations that QueryUtils accommodates. For the meantime, we are trying to avoid any more changes to QueryParser.

gregturn avatar Feb 24 '23 22:02 gregturn

I'm dropping the query-parser label and revisit-after-query-rewrite label since this involves native queries.

Frankly, this situation appears too complicated for QueryUtils to handle, and we aren't likely to approve a change there that would meet your needs. Your best best moving forward may be to implement a custom implementation. Check out https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.custom-implementations for more details on how to hook such a solution into your repository.

gregturn avatar Apr 28 '23 15:04 gregturn