Parse START TRANSACTION when followed by a semicolon
Co-authored-by: Nikhil Benesch <nikhil.benesch@gmail.com>
diff --git a/src/parser.rs b/src/parser.rs
index f771915..38bf4ef 100644
--- a/src/parser.rs
+++ b/src/parser.rs
@@ -2026,7 +2026,7 @@
TransactionMode::AccessMode(TransactionAccessMode::ReadOnly)
} else if self.parse_keywords(vec!["READ", "WRITE"]) {
TransactionMode::AccessMode(TransactionAccessMode::ReadWrite)
- } else if required || self.peek_token().is_some() {
+ } else if required {
self.expected("transaction mode", self.peek_token())?
} else {
break;
diff --git a/tests/sqlparser_common.rs b/tests/sqlparser_common.rs
index abe6e8f..ba5bd97 100644
--- a/tests/sqlparser_common.rs
+++ b/tests/sqlparser_common.rs
@@ -2455,6 +2455,17 @@
verified_stmt("START TRANSACTION ISOLATION LEVEL REPEATABLE READ");
verified_stmt("START TRANSACTION ISOLATION LEVEL SERIALIZABLE");
+ // Regression test for https://github.com/andygrove/sqlparser-rs/pull/139,
+ // in which START TRANSACTION would fail to parse if followed by a statement
+ // terminator.
+ assert_eq!(
+ parse_sql_statements("START TRANSACTION; SELECT 1"),
+ Ok(vec![
+ verified_stmt("START TRANSACTION"),
+ verified_stmt("SELECT 1"),
+ ])
+ );
+
let res = parse_sql_statements("START TRANSACTION ISOLATION LEVEL BAD");
assert_eq!(
ParserError::ParserError("Expected isolation level, found: BAD".to_string()),
@@ -2463,7 +2474,7 @@
let res = parse_sql_statements("START TRANSACTION BAD");
assert_eq!(
- ParserError::ParserError("Expected transaction mode, found: BAD".to_string()),
+ ParserError::ParserError("Expected end of statement, found: BAD".to_string()),
res.unwrap_err()
);