Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added ability to parse extension to parse_comment inside postgres dialect #1451

Merged
merged 1 commit into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1843,13 +1843,15 @@ impl fmt::Display for ShowCreateObject {
pub enum CommentObject {
Column,
Table,
Extension,
}

impl fmt::Display for CommentObject {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
CommentObject::Column => f.write_str("COLUMN"),
CommentObject::Table => f.write_str("TABLE"),
CommentObject::Extension => f.write_str("EXTENSION"),
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/dialect/postgresql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ pub fn parse_comment(parser: &mut Parser) -> Result<Statement, ParserError> {
let object_name = parser.parse_object_name(false)?;
(CommentObject::Table, object_name)
}
Token::Word(w) if w.keyword == Keyword::EXTENSION => {
let object_name = parser.parse_object_name(false)?;
(CommentObject::Extension, object_name)
}
_ => parser.expected("comment object_type", token)?,
};

Expand Down
15 changes: 15 additions & 0 deletions tests/sqlparser_postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2902,6 +2902,21 @@ fn parse_comments() {
_ => unreachable!(),
}

match pg().verified_stmt("COMMENT ON EXTENSION plpgsql IS 'comment'") {
Statement::Comment {
object_type,
object_name,
comment: Some(comment),
if_exists,
} => {
assert_eq!("comment", comment);
assert_eq!("plpgsql", object_name.to_string());
assert_eq!(CommentObject::Extension, object_type);
assert!(!if_exists);
}
_ => unreachable!(),
}

match pg().verified_stmt("COMMENT ON TABLE public.tab IS 'comment'") {
Statement::Comment {
object_type,
Expand Down
Loading