question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Vertx executeBatch not returning all rows

See original GitHub issue

Questions

Hello, I want to use pg-client executeBatch() method however the result that I am getting is not what I expect. I see that in the database several rows have been inserted but the result RowSet<Row> contains only the first inserted row. Could you please elaborate on this?

Version

version: pg-client: 3.9.5

Do you have a reproducer?

`List<Tuple> batch = new ArrayList<>(); batch.add(Tuple.of(“julien”, “Julien Viet”)); batch.add(Tuple.of(“emad”, “Emad Alblueshi”));

// Execute the prepared batch client .preparedQuery(“INSERT INTO USERS (id, name) VALUES ($1, $2) RETURNING id”) .executeBatch(batch, res -> { if (res.succeeded()) {

// Process rows
RowSet<Row> rows = res.result();
System.out.println("Got " + rows.rowCount() + " rows ");

for (Row row : rows) {
System.out.println("User id: " + row.getInteger("id"));
 }

} else { System.out.println("Batch failed " + res.cause()); } });`

Output is always the first inserted row: Got 1 rows User id: julien

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
zero88commented, Mar 1, 2021

@ivadoncheva Use this one

if (ar.succeeded()) {
    RowSet<Row> rows = ar.result();
    int[] count = new int[] {0};
    while (rows != null) {
        count[0]++;
        rows.iterator().forEachRemaining(row -> {
            System.out.println(row.toJson());
        });
        rows = rows.next();
    }
    ctx.verify(() -> Assertions.assertTrue(count[0] > 0));
} else {
    ctx.failNow(ar.cause());
}
0reactions
ivadonchevacommented, Mar 1, 2021

Thanks, @zero88. This works!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Vertx executeBatch not returning all rows - Stack Overflow
The code example below will fix the issue and get all rows. client .preparedQuery("INSERT INTO color (color_name) VALUES ($1) RETURNING color_id ...
Read more >
Quarkus sql client PreparedQuery.executeBatch number of ...
Final. We are using the preparedQuery.executeBatch as below, but the rowCount always returns 1 no matter how many rows it updated. import io....
Read more >
PreparedQuery (Vert.x Stack - Docs 4.3.6 API)
Execute the query with a batch of tuples. Use the specified mapper for mapping Row to <U> .
Read more >
Reactive SQL Clients - Quarkus
src/main/java/org/acme/vertx/Fruit.java. private static Fruit from(Row row) { return new Fruit(row.getLong("id"), row.getString("name")); }. Putting it all ...
Read more >
SQL common | Eclipse Vert.x
There are times when you will want to run a single SQL operation, e.g.: a single select of a row, or a update...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found