Skip to content

Commit d601ba1

Browse files
committed
added ability to parse COMMENT ON EXTENSION to parse_comment inside postgres dialect
1 parent 1e0460a commit d601ba1

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

src/ast/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1843,13 +1843,15 @@ impl fmt::Display for ShowCreateObject {
18431843
pub enum CommentObject {
18441844
Column,
18451845
Table,
1846+
Extension,
18461847
}
18471848

18481849
impl fmt::Display for CommentObject {
18491850
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
18501851
match self {
18511852
CommentObject::Column => f.write_str("COLUMN"),
18521853
CommentObject::Table => f.write_str("TABLE"),
1854+
CommentObject::Extension => f.write_str("EXTENSION"),
18531855
}
18541856
}
18551857
}

src/dialect/postgresql.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,10 @@ pub fn parse_comment(parser: &mut Parser) -> Result<Statement, ParserError> {
205205
let object_name = parser.parse_object_name(false)?;
206206
(CommentObject::Table, object_name)
207207
}
208+
Token::Word(w) if w.keyword == Keyword::EXTENSION => {
209+
let object_name = parser.parse_object_name(false)?;
210+
(CommentObject::Extension, object_name)
211+
}
208212
_ => parser.expected("comment object_type", token)?,
209213
};
210214

tests/sqlparser_postgres.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2902,6 +2902,21 @@ fn parse_comments() {
29022902
_ => unreachable!(),
29032903
}
29042904

2905+
match pg().verified_stmt("COMMENT ON EXTENSION plpgsql IS 'comment'") {
2906+
Statement::Comment {
2907+
object_type,
2908+
object_name,
2909+
comment: Some(comment),
2910+
if_exists,
2911+
} => {
2912+
assert_eq!("comment", comment);
2913+
assert_eq!("plpgsql", object_name.to_string());
2914+
assert_eq!(CommentObject::Extension, object_type);
2915+
assert!(!if_exists);
2916+
}
2917+
_ => unreachable!(),
2918+
}
2919+
29052920
match pg().verified_stmt("COMMENT ON TABLE public.tab IS 'comment'") {
29062921
Statement::Comment {
29072922
object_type,

0 commit comments

Comments
 (0)