diff --git a/src/ast/mod.rs b/src/ast/mod.rs index 0b0893d7e4..8e5391dfd8 100644 --- a/src/ast/mod.rs +++ b/src/ast/mod.rs @@ -6259,7 +6259,7 @@ impl fmt::Display for Statement { }; write!(f, "ON {object_type} {object_name} IS ")?; if let Some(c) = comment { - write!(f, "'{c}'") + write!(f, "'{}'", value::escape_single_quote_string(c)) } else { write!(f, "NULL") } diff --git a/tests/sqlparser_common.rs b/tests/sqlparser_common.rs index 7627f39185..6563a0d8f6 100644 --- a/tests/sqlparser_common.rs +++ b/tests/sqlparser_common.rs @@ -23323,3 +23323,17 @@ fn display_refresh_materialized_view_propagates_write_errors() { assert_eq!(write!(writer, "{statement}"), Err(fmt::Error), "{rejected}"); } } + +#[test] +fn parse_comment_on_escaped_comment_value() { + let dialects = all_dialects_where(|d| d.supports_comment_on()); + + match dialects.verified_stmt("COMMENT ON COLUMN t.id IS 'Column ''id'' on t'") { + Statement::Comment { + comment: Some(comment), + .. + } => assert_eq!("Column 'id' on t", comment), + _ => unreachable!(), + } + dialects.verified_stmt("COMMENT ON SEQUENCE asdf IS 'won''t work'"); +}