Skip to content

Commit da47b0a

Browse files
authored
fix: recognize ABORT statements for PostgreSQL (#2479)
PostgreSQL supports the `ABORT [ WORK | TRANSACTION ] [ AND [ NO ] CHAIN ]` statement in addition to the more common ROLLBACK. See https://www.postgresql.org/docs/current/sql-abort.html
1 parent 7c5b606 commit da47b0a

File tree

6 files changed

+246
-2023
lines changed

6 files changed

+246
-2023
lines changed

google-cloud-spanner/src/main/resources/com/google/cloud/spanner/connection/PG_ClientSideStatements.json

+6-3
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,16 @@
224224
"examplePrerequisiteStatements": ["begin transaction"]
225225
},
226226
{
227-
"name": "ROLLBACK [TRANSACTION | WORK] [AND NO CHAIN]",
227+
"name": "{ROLLBACK | ABORT} [TRANSACTION | WORK] [AND NO CHAIN]",
228228
"executorName": "ClientSideStatementNoParamExecutor",
229229
"resultType": "NO_RESULT",
230230
"statementType": "ROLLBACK",
231-
"regex": "(?is)\\A\\s*(?:rollback)(?:\\s+transaction|\\s+work)?(?:\\s+and\\s+no\\s+chain)?\\s*\\z",
231+
"regex": "(?is)\\A\\s*(?:rollback|abort)(?:\\s+transaction|\\s+work)?(?:\\s+and\\s+no\\s+chain)?\\s*\\z",
232232
"method": "statementRollback",
233-
"exampleStatements": ["rollback", "rollback transaction", "rollback work", "rollback and no chain", "rollback transaction and no chain", "rollback work and no chain"],
233+
"exampleStatements": [
234+
"rollback", "rollback transaction", "rollback work", "rollback and no chain", "rollback transaction and no chain", "rollback work and no chain",
235+
"abort", "abort transaction", "abort work", "abort and no chain", "abort transaction and no chain", "abort work and no chain"
236+
],
234237
"examplePrerequisiteStatements": ["begin transaction"]
235238
},
236239
{

google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/ClientSideStatementsTest.java

+16
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,22 @@ public void testClientSideStatementType() {
7878
assertEquals(
7979
ClientSideStatementType.ROLLBACK,
8080
parser.parse(Statement.of("ROLLBACK TRANSACTION")).getClientSideStatementType());
81+
if (dialect == Dialect.POSTGRESQL) {
82+
assertEquals(
83+
ClientSideStatementType.ROLLBACK,
84+
parser.parse(Statement.of("ABORT")).getClientSideStatementType());
85+
assertEquals(
86+
ClientSideStatementType.ROLLBACK,
87+
parser.parse(Statement.of("ABORT TRANSACTION")).getClientSideStatementType());
88+
assertEquals(
89+
ClientSideStatementType.ROLLBACK,
90+
parser.parse(Statement.of("ABORT WORK")).getClientSideStatementType());
91+
assertEquals(
92+
ClientSideStatementType.ROLLBACK,
93+
parser
94+
.parse(Statement.of("ABORT TRANSACTION and no chain"))
95+
.getClientSideStatementType());
96+
}
8197

8298
for (ClientSideStatementImpl statement : parser.getClientSideStatements()) {
8399
assertNotNull(

0 commit comments

Comments
 (0)