mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-21 14:40:18 +00:00
add support for SAVEPOINT statement (#438)
This commit is contained in:
parent
497a3b0e1b
commit
12a3e97ef3
3 changed files with 22 additions and 0 deletions
|
@ -956,6 +956,8 @@ pub enum Statement {
|
|||
/// A SQL query that specifies what to explain
|
||||
statement: Box<Statement>,
|
||||
},
|
||||
/// SAVEPOINT -- define a new savepoint within the current transaction
|
||||
Savepoint { name: Ident },
|
||||
// MERGE INTO statement, based on Snowflake. See <https://docs.snowflake.com/en/sql-reference/sql/merge.html>
|
||||
Merge {
|
||||
// Specifies the table to merge
|
||||
|
@ -1619,6 +1621,10 @@ impl fmt::Display for Statement {
|
|||
write!(f, "NULL")
|
||||
}
|
||||
}
|
||||
Statement::Savepoint { name } => {
|
||||
write!(f, "SAVEPOINT ")?;
|
||||
write!(f, "{}", name)
|
||||
}
|
||||
Statement::Merge {
|
||||
table,
|
||||
source,
|
||||
|
|
|
@ -179,6 +179,7 @@ impl<'a> Parser<'a> {
|
|||
// standard `START TRANSACTION` statement. It is supported
|
||||
// by at least PostgreSQL and MySQL.
|
||||
Keyword::BEGIN => Ok(self.parse_begin()?),
|
||||
Keyword::SAVEPOINT => Ok(self.parse_savepoint()?),
|
||||
Keyword::COMMIT => Ok(self.parse_commit()?),
|
||||
Keyword::ROLLBACK => Ok(self.parse_rollback()?),
|
||||
Keyword::ASSERT => Ok(self.parse_assert()?),
|
||||
|
@ -367,6 +368,11 @@ impl<'a> Parser<'a> {
|
|||
Ok(Statement::Assert { condition, message })
|
||||
}
|
||||
|
||||
pub fn parse_savepoint(&mut self) -> Result<Statement, ParserError> {
|
||||
let name = self.parse_identifier()?;
|
||||
Ok(Statement::Savepoint { name })
|
||||
}
|
||||
|
||||
/// Parse an expression prefix
|
||||
pub fn parse_prefix(&mut self) -> Result<Expr, ParserError> {
|
||||
// PostgreSQL allows any string literal to be preceded by a type name, indicating that the
|
||||
|
|
|
@ -871,6 +871,16 @@ fn test_transaction_statement() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_savepoint() {
|
||||
match pg().verified_stmt("SAVEPOINT test1") {
|
||||
Statement::Savepoint { name } => {
|
||||
assert_eq!(Ident::new("test1"), name);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_comments() {
|
||||
match pg().verified_stmt("COMMENT ON COLUMN tab.name IS 'comment'") {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue