Skip to content

Commit

Permalink
Pg doc: incorrect snippet for retrieval of batched insert with return…
Browse files Browse the repository at this point in the history
…ing clause

See #1440

The last rowset was missed because, for this one, rowset.next() is always null.

Signed-off-by: Thomas Segismont <[email protected]>
  • Loading branch information
tsegismont committed May 27, 2024
1 parent d1011cb commit d669e60
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions vertx-pg-client/src/main/java/examples/PgClientExamples.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
import io.vertx.core.json.JsonObject;
import io.vertx.core.net.PemTrustOptions;
import io.vertx.docgen.Source;
import io.vertx.pgclient.*;
import io.vertx.pgclient.PgBuilder;
import io.vertx.pgclient.PgConnectOptions;
import io.vertx.pgclient.PgConnection;
import io.vertx.pgclient.SslMode;
import io.vertx.pgclient.pubsub.PgSubscriber;
import io.vertx.sqlclient.*;
import io.vertx.sqlclient.data.Numeric;
Expand Down Expand Up @@ -773,7 +776,7 @@ public void batchReturning(SqlClient client) {
.preparedQuery("INSERT INTO color (color_name) VALUES ($1) RETURNING color_id")
.executeBatch(Arrays.asList(Tuple.of("white"), Tuple.of("red"), Tuple.of("blue")))
.onSuccess(res -> {
for (RowSet<Row> rows = res;rows.next() != null;rows = rows.next()) {
for (RowSet<Row> rows = res; rows != null; rows = rows.next()) {
Integer colorId = rows.iterator().next().getInteger("color_id");
System.out.println("generated key: " + colorId);
}
Expand Down

0 comments on commit d669e60

Please sign in to comment.