mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-22 06:54:07 +00:00
feat: add FOR UPDATE/FOR SHARE clause (#418)
* feat: add FOR UPDATE/FOR SHARE clause * refactor: LockType enum variant name Co-authored-by: gamife <gamife9886@gmail.com>
This commit is contained in:
parent
899f91b1f6
commit
0b5178d7e7
6 changed files with 59 additions and 4 deletions
|
@ -2649,6 +2649,12 @@ impl<'a> Parser<'a> {
|
|||
None
|
||||
};
|
||||
|
||||
let lock = if self.parse_keyword(Keyword::FOR) {
|
||||
Some(self.parse_lock()?)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
Ok(Query {
|
||||
with,
|
||||
body,
|
||||
|
@ -2656,6 +2662,7 @@ impl<'a> Parser<'a> {
|
|||
limit,
|
||||
offset,
|
||||
fetch,
|
||||
lock,
|
||||
})
|
||||
} else {
|
||||
let insert = self.parse_insert()?;
|
||||
|
@ -2667,6 +2674,7 @@ impl<'a> Parser<'a> {
|
|||
order_by: vec![],
|
||||
offset: None,
|
||||
fetch: None,
|
||||
lock: None,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -3639,6 +3647,15 @@ impl<'a> Parser<'a> {
|
|||
})
|
||||
}
|
||||
|
||||
/// Parse a FOR UPDATE/FOR SHARE clause
|
||||
pub fn parse_lock(&mut self) -> Result<LockType, ParserError> {
|
||||
match self.expect_one_of_keywords(&[Keyword::UPDATE, Keyword::SHARE])? {
|
||||
Keyword::UPDATE => Ok(LockType::Update),
|
||||
Keyword::SHARE => Ok(LockType::Share),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parse_values(&mut self) -> Result<Values, ParserError> {
|
||||
let values = self.parse_comma_separated(|parser| {
|
||||
parser.expect_token(&Token::LParen)?;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue