[jOOQ/jOOQ#13660] PostgreSQL ON CONFLICT .. WHERE .. DO NOTHING generates not valid SQL

This commit is contained in:
Lukas Eder 2022-06-13 11:57:10 +02:00
parent f915b55590
commit bb9900ba8f

View File

@ -386,12 +386,7 @@ implements
ctx.sql('(').qualify(false, c -> c.visit(new FieldsImpl<>(table().getPrimaryKey().getFields()))).sql(')');
}
if (onConflictWhere.hasWhere())
ctx.qualify(false, c -> c
.formatSeparator()
.visit(K_WHERE)
.sql(' ')
.visit(onConflictWhere.getWhere()));
acceptOnConflictWhere(ctx);
ctx.formatSeparator()
.visit(K_DO_UPDATE)
@ -536,12 +531,7 @@ implements
else {
if (onConflict != null && onConflict.size() > 0) {
ctx.sql(" (").visit(onConflict).sql(')');
if (onConflictWhere.hasWhere())
ctx.formatSeparator()
.visit(K_WHERE)
.sql(' ')
.visit(onConflictWhere.getWhere());
acceptOnConflictWhere(ctx);
}
@ -626,6 +616,17 @@ implements
ctx.end(INSERT_RETURNING);
}
private final void acceptOnConflictWhere(Context<?> ctx) {
if (onConflictWhere.hasWhere())
// [#11732] [#13660] Avoid qualification, which wasn't supported in older PG versions
ctx.qualify(false, c -> c
.formatSeparator()
.visit(K_WHERE)
.sql(' ')
.visit(onConflictWhere.getWhere()));
}
@Override
public final Clause[] clauses(Context<?> ctx) {
return CLAUSES;