pgjdbc/pgjdbc GitHub issues and pull requests (mirror)  
help / color / mirror / Atom feed
From: zhurs (@zhurs) <[email protected]>
To: pgjdbc/pgjdbc <[email protected]>
Subject: Re: [pgjdbc/pgjdbc] issue #2918: Set defaultRowFetchSize=10000 by default to improve app stability
Date: Wed, 12 Jul 2023 08:16:33 +0000
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>

It seems that it is an incompatible change - for insert..returning statements, if the size of the result is more than fetchSize method executeUpdate returns -1, here is a small example:

```java
conn.prepareStatement("DROP TABLE IF EXISTS test_table").execute();
conn.prepareStatement("CREATE TABLE IF NOT EXISTS test_table (id SERIAL PRIMARY KEY, cnt INT NOT NULL)").execute();

for (var fetchSize : List.of(0, 1, 2, 3)) {
    System.out.println("FetchSize=" + fetchSize);

    try (var stmt = conn.prepareStatement("INSERT INTO test_table (cnt) VALUES (1), (2) RETURNING id", RETURN_GENERATED_KEYS)) {
        stmt.setFetchSize(fetchSize);

        var ret = stmt.executeUpdate();
        System.out.println("executeUpdate result: " + ret);

        var rs = stmt.getGeneratedKeys();
        System.out.print("ids: ");
        while (rs.next()) {
            System.out.print(rs.getInt(1) + " ");
        }
        System.out.print("\n\n");
    }
}
```

Output:
```
FetchSize=0
executeUpdate result: 2
ids: 1 2 

FetchSize=1
executeUpdate result: -1
ids: 3 4 

FetchSize=2
executeUpdate result: -1
ids: 5 6 

FetchSize=3
executeUpdate result: 2
ids: 7 8 
```

Also, -1 is not documented and contradicts with jdbc specification:

> executeUpdate Returns:
> either (1) the row count for SQL Data Manipulation Language (DML) statements or (2) 0 for SQL statements that return nothing

view thread (18+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: github://pgjdbc/pgjdbc
  Cc: [email protected], [email protected]
  Subject: Re: [pgjdbc/pgjdbc] issue #2918: Set defaultRowFetchSize=10000 by default to improve app stability
  In-Reply-To: <<[email protected]>>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox