Skip to content

Conversation

olavloite
Copy link
Collaborator

Adds support for including transaction options in BEGIN statements, like:

BEGIN READ ONLY;
BEGIN READ WRITE;
BEGIN TRANSACTION ISOLATION LEVEL REPEATABLE READ;
BEGIN READ WRITE, ISOLATION LEVEL SERIALIZABLE;

Parse SET TRANSACTION statements and translate these to SET LOCAL statements.
SET TRANSACTION may only be executed in a transaction block, and can only be
used for a specific, limited set of connection properties. The syntax is
specified by the SQL standard and PostgreSQL.

See also https://www.postgresql.org/docs/current/sql-set-transaction.html

This change only adds partial support. The following features will be added
in future changes:
1. SET TRANSACTION READ {WRITE | ONLY} is not picked up by the driver, as
   the type of transaction is set directly when BeginTx is called. A
   refactor of this transaction handling is needed to be able to pick up
   SET TRANSACTION READ ONLY / SET TRANSACTION READ WRITE statements that
   are executed after BeginTx has been called.
2. PostgreSQL allows multiple transaction modes to be set in a single
   SET TRANSACTION statement. E.g. the following is allowed:
   SET TRANSACTION READ WRITE, ISOLATION LEVEL SERIALIZABLE
   The current implementation only supports one transaction mode per
   SET statement.
Adds support for including transaction options in BEGIN statements, like:

```sql
BEGIN READ ONLY;
BEGIN READ WRITE;
BEGIN TRANSACTION ISOLATION LEVEL REPEATABLE READ;
BEGIN READ WRITE, ISOLATION LEVEL SERIALIZABLE;
```
@olavloite olavloite requested a review from a team as a code owner October 6, 2025 10:31
rahul2393
rahul2393 previously approved these changes Oct 6, 2025
Base automatically changed from parse-set-transaction to main October 7, 2025 17:00
@olavloite olavloite dismissed rahul2393’s stale review October 7, 2025 17:00

The base branch was changed.

@olavloite olavloite merged commit 49e945e into main Oct 7, 2025
28 checks passed
@olavloite olavloite deleted the parse-begin-transaction-options branch October 7, 2025 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants