Subject: [pgjdbc/pgjdbc] PR #3996: fix: enable cursor-based fetching in extended protocol when transaction started via SQL command

From: "vlsi (@vlsi)" <[email-masked]>
Date: Mon, 23 Mar 2026 12:14:28 +0000

When a user starts a transaction with `START TRANSACTION` or `BEGIN`SQL commands (instead of `setAutoCommit(false)`), cursor-based fetching was not activated because `PgStatement.executeInternal()` only checked `getAutoCommit()`.
The server is already in a transaction block in this case, so server-side cursors will survive across fetches.

The fix checks the actual server transaction state in addition to the autoCommit flag.

Fixes https://github.com/pgjdbc/pgjdbc/issues/3993

---

From: "davecramer (@davecramer)" <[email-masked]>
Date: Mon, 23 Mar 2026 15:03:49 +0000

we should probably check the transaction state before we do anything on the connection as well.

---

From: "vlsi (@vlsi)" <[email-masked]>
Date: Mon, 23 Mar 2026 15:09:22 +0000

What do you mean?

---

From: "davecramer (@davecramer)" <[email-masked]>
Date: Mon, 23 Mar 2026 15:12:22 +0000

Well since we are getting the transaction state from the queryExecutor just want to put a check in there to make sure that the query executor is instantiated correctly. So if we don't execute any statements what is the transaction state ?

---

From: "vlsi (@vlsi)" <[email-masked]>
Date: Mon, 23 Mar 2026 15:57:38 +0000

I am not following your question.
There's a valid API use, and currently it skips using cursor (==It loads everything at once in a single go).
As far as I understand, the code wants to skip cursor in certain cases so the cursor does not disappear mid-fetch.

The condition for "use vs not use" the cursor was not quite right, so the condition could be lifted.

I don't understand how your question maps to the test case at hand

---

From: "vlsi (@vlsi)" <[email-masked]>
Date: Mon, 23 Mar 2026 16:00:56 +0000

Do you mean "add a test case that a fresh connection responds IDLE transaction state"?

---

From: "davecramer (@davecramer)" <[email-masked]>
Date: Mon, 23 Mar 2026 17:18:38 +0000

> Do you mean "add a test case that a fresh connection responds IDLE transaction state"?

yes

---

From: "vlsi (@vlsi)" <[email-masked]>
Date: Tue, 24 Mar 2026 07:06:10 +0000

I've filed transaction state tests under https://github.com/pgjdbc/pgjdbc/pull/4006