[jOOQ/jOOQ#5214] MySQL 8.0.20 EXCLUDED emulation should name the table t

In various emulations, we're already calling auxiliary tables t, so this alias should also be applied to the EXCLUDED emulation, which benefits cases where INSERT .. SELECT is used and stored client side computed columns are involved. Re-wrapping the SELECT query to generate an EXCLUDED alias would only further complicate the logic.
This commit is contained in:
Lukas Eder 2022-05-18 16:24:54 +02:00
parent 939ce28117
commit 28f3a4f3ce
2 changed files with 4 additions and 6 deletions

View File

@ -111,7 +111,7 @@ implements
ctx.visit(N_EXCLUDED).sql('.').qualify(false, c -> c.visit(field));
ctx.visit(name("t")).sql('.').qualify(false, c -> c.visit(field));
break;
}

View File

@ -83,9 +83,7 @@ import static org.jooq.impl.Keywords.K_ON_DUPLICATE_KEY_UPDATE;
import static org.jooq.impl.Keywords.K_SET;
import static org.jooq.impl.Keywords.K_VALUES;
import static org.jooq.impl.Keywords.K_WHERE;
import static org.jooq.impl.Names.N_EXCLUDED;
import static org.jooq.impl.QueryPartListView.wrap;
import static org.jooq.impl.Tools.EMPTY_FIELD;
import static org.jooq.impl.Tools.aliasedFields;
import static org.jooq.impl.Tools.anyMatch;
import static org.jooq.impl.Tools.collect;
@ -454,9 +452,9 @@ implements
Set<Field<?>> keys = toSQLInsert(ctx, requireNewMySQLExcludedEmulation);
// [#5214] The alias only applies with INSERT .. VALUES
if (requireNewMySQLExcludedEmulation && select == null)
if (requireNewMySQLExcludedEmulation && select == null && !Tools.anyComputedOnClientStoredFields(table))
ctx.formatSeparator()
.visit(K_AS).sql(' ').visit(N_EXCLUDED);
.visit(K_AS).sql(' ').visit(name("t"));
ctx.formatSeparator()
.start(INSERT_ON_DUPLICATE_KEY_UPDATE)
@ -691,7 +689,7 @@ implements
if (requireNewMySQLExcludedEmulation)
s = selectFrom(s.asTable(DSL.table(N_EXCLUDED), keysFlattened));
s = selectFrom(s.asTable(DSL.table(name("t")), keysFlattened));
// [#8353] TODO: Support overlapping embeddables
toSQLInsertSelect(ctx, s);