Skip to content

Commit 8ccb87a

Browse files
added ability to parse extension to parse_comment inside postgres dialect (#1451)
1 parent e849f7f commit 8ccb87a

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

src/ast/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1855,13 +1855,15 @@ impl fmt::Display for ShowCreateObject {
18551855
pub enum CommentObject {
18561856
Column,
18571857
Table,
1858+
Extension,
18581859
}
18591860

18601861
impl fmt::Display for CommentObject {
18611862
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
18621863
match self {
18631864
CommentObject::Column => f.write_str("COLUMN"),
18641865
CommentObject::Table => f.write_str("TABLE"),
1866+
CommentObject::Extension => f.write_str("EXTENSION"),
18651867
}
18661868
}
18671869
}

src/dialect/postgresql.rs

+4
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

+15
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)