Message-ID: From: "zhurs (@zhurs)" To: "pgjdbc/pgjdbc" Date: Wed, 12 Jul 2023 08:16:33 +0000 Subject: Re: [pgjdbc/pgjdbc] issue #2918: Set defaultRowFetchSize=10000 by default to improve app stability In-Reply-To: References: List-Id: X-GitHub-Author-Login: zhurs X-GitHub-Comment-Id: 1632056820 X-GitHub-Comment-Type: issue_comment X-GitHub-Edited-At: 2023-07-21T15:16:57Z X-GitHub-Issue: 2918 X-GitHub-Repo: pgjdbc/pgjdbc X-GitHub-Type: comment X-GitHub-Url: https://github.com/pgjdbc/pgjdbc/issues/2918#issuecomment-1632056820 Content-Type: text/plain; charset=utf-8 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