Skip to content

Commit

Permalink
[#5688] PostgreSQL RETURNING <col> AS <alias> is not rendered correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaseder committed Oct 18, 2017
1 parent bb0a959 commit e8185bd
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions jOOQ/src/main/java/org/jooq/impl/AbstractDMLQuery.java
Expand Up @@ -109,15 +109,15 @@ abstract class AbstractDMLQuery<R extends Record> extends AbstractQuery {

final WithImpl with;
final Table<R> table;
final QueryPartList<Field<?>> returning;
final SelectFieldList returning;
Result<R> returned;

AbstractDMLQuery(Configuration configuration, WithImpl with, Table<R> table) {
super(configuration);

this.with = with;
this.table = table;
this.returning = new QueryPartList<Field<?>>();
this.returning = new SelectFieldList();
}

// @Override
Expand Down Expand Up @@ -166,6 +166,12 @@ public final void accept(Context<?> ctx) {
if (with != null)
ctx.visit(with).formatSeparator();

boolean previousDeclareFields = ctx.declareFields();








Expand Down Expand Up @@ -312,12 +318,18 @@ final void toSQLReturning(Context<?> ctx) {
if (!returning.isEmpty()) {
switch (ctx.family()) {
case FIREBIRD:
case POSTGRES:
case POSTGRES: {
boolean previous = ctx.declareFields();

ctx.formatSeparator()
.visit(K_RETURNING)
.sql(' ')
.visit(returning);
.declareFields(true)
.visit(returning)
.declareFields(previous);

break;
}

default:
// Other dialects don't render a RETURNING clause, but
Expand Down

0 comments on commit e8185bd

Please sign in to comment.