Add support of COMMENT ON syntax for Snowflake (#1516)

This commit is contained in:
hulk 2024-11-13 21:23:33 +08:00 committed by GitHub
parent 76322baf2f
commit 6d907d3adc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 164 additions and 102 deletions

View file

@ -28,7 +28,7 @@
// limitations under the License.
use log::debug;
use crate::ast::{CommentObject, ObjectName, Statement, UserDefinedTypeRepresentation};
use crate::ast::{ObjectName, Statement, UserDefinedTypeRepresentation};
use crate::dialect::{Dialect, Precedence};
use crate::keywords::Keyword;
use crate::parser::{Parser, ParserError};
@ -136,9 +136,7 @@ impl Dialect for PostgreSqlDialect {
}
fn parse_statement(&self, parser: &mut Parser) -> Option<Result<Statement, ParserError>> {
if parser.parse_keyword(Keyword::COMMENT) {
Some(parse_comment(parser))
} else if parser.parse_keyword(Keyword::CREATE) {
if parser.parse_keyword(Keyword::CREATE) {
parser.prev_token(); // unconsume the CREATE in case we don't end up parsing anything
parse_create(parser)
} else {
@ -206,42 +204,11 @@ impl Dialect for PostgreSqlDialect {
fn supports_factorial_operator(&self) -> bool {
true
}
}
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();
let (object_type, object_name) = match token.token {
Token::Word(w) if w.keyword == Keyword::COLUMN => {
let object_name = parser.parse_object_name(false)?;
(CommentObject::Column, object_name)
}
Token::Word(w) if w.keyword == Keyword::TABLE => {
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)?,
};
parser.expect_keyword(Keyword::IS)?;
let comment = if parser.parse_keyword(Keyword::NULL) {
None
} else {
Some(parser.parse_literal_string()?)
};
Ok(Statement::Comment {
object_type,
object_name,
comment,
if_exists,
})
/// see <https://www.postgresql.org/docs/current/sql-comment.html>
fn supports_comment_on(&self) -> bool {
true
}
}
pub fn parse_create(parser: &mut Parser) -> Option<Result<Statement, ParserError>> {