[jOOQ/jOOQ#13571] Emulate the PostgreSQL ON CONFLICT .. EXCLUDED pseudo table in MERGE emulation

This commit is contained in:
Lukas Eder 2022-05-18 09:17:47 +02:00
parent 7cb60cf8ce
commit 8d668b00b5

View File

@ -824,7 +824,7 @@ implements
|| onConstraint != null
|| !table().getKeys().isEmpty()) {
Table<?> t = null;
Table<?> t;
Set<Field<?>> k = insertMaps.keysFlattened(ctx, null);
Collection<Field<?>> f = null;
@ -857,6 +857,8 @@ implements
else
t = s.asTable("t", map(f, Field::getName, String[]::new));
}
else
t = null;
MergeOnConditionStep<R> on = t != null
? ctx.dsl().mergeInto(table())
@ -872,6 +874,19 @@ implements
if (onDuplicateKeyUpdate) {
final FieldMapForUpdate um = updateMapComputedOnClientStored(ctx);
// [#5214] [#13571] PostgreSQL EXCLUDED pseudo table emulation
// The InsertQueryImpl uses "t" as table name
um.replaceAll((key, v) -> {
if (t != null && v instanceof Excluded<?> e) {
if (t.field(e.$field()) != null)
return Tools.qualify(t, e.$field());
else
return Tools.qualify(table(), e.$field());
}
else
return v;
});
notMatched = condition.hasWhere()
? on.whenMatchedAnd(condition.getWhere()).thenUpdate().set(um)
: on.whenMatchedThenUpdate().set(um);