mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-22 15:04:04 +00:00
Implement ASSERT statement (#226)
As supported by PostgreSQL and BigQuery (with some differences between them)
This commit is contained in:
parent
5cab18963e
commit
c24b0e01db
4 changed files with 78 additions and 0 deletions
|
@ -148,6 +148,7 @@ impl Parser {
|
|||
Keyword::BEGIN => Ok(self.parse_begin()?),
|
||||
Keyword::COMMIT => Ok(self.parse_commit()?),
|
||||
Keyword::ROLLBACK => Ok(self.parse_rollback()?),
|
||||
Keyword::ASSERT => Ok(self.parse_assert()?),
|
||||
_ => self.expected("an SQL statement", Token::Word(w)),
|
||||
},
|
||||
Token::LParen => {
|
||||
|
@ -179,6 +180,22 @@ impl Parser {
|
|||
}
|
||||
Ok(expr)
|
||||
}
|
||||
pub fn parse_assert(&mut self) -> Result<Statement, ParserError> {
|
||||
let condition = self.parse_expr()?;
|
||||
let (separator, message) = if self.consume_token(&Token::Comma) {
|
||||
(",".to_string(), Some(self.parse_expr()?))
|
||||
} else if self.parse_keyword(Keyword::AS) {
|
||||
("AS".to_string(), Some(self.parse_expr()?))
|
||||
} else {
|
||||
("".to_string(), None)
|
||||
};
|
||||
|
||||
Ok(Statement::Assert {
|
||||
condition,
|
||||
separator,
|
||||
message,
|
||||
})
|
||||
}
|
||||
|
||||
/// Parse an expression prefix
|
||||
pub fn parse_prefix(&mut self) -> Result<Expr, ParserError> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue