Skip to content

Alias for table in deleteFrom #488

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
apozo-copyright opened this issue May 25, 2022 · 1 comment · Fixed by #489
Closed

Alias for table in deleteFrom #488

apozo-copyright opened this issue May 25, 2022 · 1 comment · Fixed by #489

Comments

@apozo-copyright
Copy link

apozo-copyright commented May 25, 2022

Please, add support for alias in deleteFrom, otherwise there is no way of using it with exists condition when there are ambiguous columns.

deleteFrom(ENTITY_A).
    where(notExists(
        select(ENTITY_B.id).from(ENTITY_B).where(ENTITY_B.a_id, isEqualTo(ENTITY_A.id))))
    .build().render(RenderingStrategies.MYBATIS3);

If columns A.id & B.a_id have the same name (let's say 'aId'), the resulting sql doesn't work as confuse the column from A with the one in B. This is translated to:
delete from A where not exists (select id from b where aId = aId);
It doesn't matter if an alias is used for B, it's still considering the right part of the equal a column from B:
delete from A where not exists (select id from b as alias where alias.aId = aId);

@jeffgbutler
Copy link
Member

Good catch! I will add this.

jeffgbutler added a commit that referenced this issue May 26, 2022
Add Ability to Specify Table Aliases on DELETE and UPDATE Statements
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants