From 8ccb87a8355858ccb06ffc20484657cd7980d78c Mon Sep 17 00:00:00 2001 From: Maxwell Knight <107858496+MaxwellKnight@users.noreply.github.com> Date: Fri, 4 Oct 2024 23:07:26 +0300 Subject: [PATCH] added ability to parse extension to parse_comment inside postgres dialect (#1451) --- src/ast/mod.rs | 2 ++ src/dialect/postgresql.rs | 4 ++++ tests/sqlparser_postgres.rs | 15 +++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/src/ast/mod.rs b/src/ast/mod.rs index 57cd401d3..8c4bc25af 100644 --- a/src/ast/mod.rs +++ b/src/ast/mod.rs @@ -1855,6 +1855,7 @@ impl fmt::Display for ShowCreateObject { pub enum CommentObject { Column, Table, + Extension, } impl fmt::Display for CommentObject { @@ -1862,6 +1863,7 @@ impl fmt::Display for CommentObject { match self { CommentObject::Column => f.write_str("COLUMN"), CommentObject::Table => f.write_str("TABLE"), + CommentObject::Extension => f.write_str("EXTENSION"), } } } diff --git a/src/dialect/postgresql.rs b/src/dialect/postgresql.rs index 945c4fcc0..2a66705bb 100644 --- a/src/dialect/postgresql.rs +++ b/src/dialect/postgresql.rs @@ -205,6 +205,10 @@ pub fn parse_comment(parser: &mut Parser) -> Result { 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)?, }; diff --git a/tests/sqlparser_postgres.rs b/tests/sqlparser_postgres.rs index 9ba3e5dbc..735b87b5d 100644 --- a/tests/sqlparser_postgres.rs +++ b/tests/sqlparser_postgres.rs @@ -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,