mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-10-19 18:27:14 +00:00
support IF EXISTS in COMMENT statements (#831)
* support IF EXISTS in COMMENT statements Signed-off-by: Pawel Leszczynski <leszczynski.pawel@gmail.com> * Update src/ast/mod.rs Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org> --------- Signed-off-by: Pawel Leszczynski <leszczynski.pawel@gmail.com> Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
This commit is contained in:
parent
548191814c
commit
4ff3aeb040
3 changed files with 19 additions and 2 deletions
|
@ -1487,6 +1487,9 @@ pub enum Statement {
|
|||
object_type: CommentObject,
|
||||
object_name: ObjectName,
|
||||
comment: Option<String>,
|
||||
/// An optional `IF EXISTS` clause. (Non-standard.)
|
||||
/// See <https://docs.snowflake.com/en/sql-reference/sql/comment>
|
||||
if_exists: bool,
|
||||
},
|
||||
/// `COMMIT [ TRANSACTION | WORK ] [ AND [ NO ] CHAIN ]`
|
||||
Commit { chain: bool },
|
||||
|
@ -2637,8 +2640,13 @@ impl fmt::Display for Statement {
|
|||
object_type,
|
||||
object_name,
|
||||
comment,
|
||||
if_exists,
|
||||
} => {
|
||||
write!(f, "COMMENT ON {object_type} {object_name} IS ")?;
|
||||
write!(f, "COMMENT ")?;
|
||||
if *if_exists {
|
||||
write!(f, "IF EXISTS ")?
|
||||
};
|
||||
write!(f, "ON {object_type} {object_name} IS ")?;
|
||||
if let Some(c) = comment {
|
||||
write!(f, "'{c}'")
|
||||
} else {
|
||||
|
|
|
@ -49,6 +49,8 @@ impl Dialect for PostgreSqlDialect {
|
|||
}
|
||||
|
||||
pub fn parse_comment(parser: &mut Parser) -> Result<Statement, ParserError> {
|
||||
let if_exists = parser.parse_keywords(&[Keyword::IF, Keyword::EXISTS]);
|
||||
|
||||
parser.expect_keyword(Keyword::ON)?;
|
||||
let token = parser.next_token();
|
||||
|
||||
|
@ -74,5 +76,6 @@ pub fn parse_comment(parser: &mut Parser) -> Result<Statement, ParserError> {
|
|||
object_type,
|
||||
object_name,
|
||||
comment,
|
||||
if_exists,
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue