Format the internal LIKE option error arm and cover LIKE errors and Display write errors
diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 698f00b..b8e0004 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs
@@ -9790,9 +9790,11 @@ Keyword::INDEXES => CreateTableLikeProperty::Indexes, Keyword::STATISTICS => CreateTableLikeProperty::Statistics, Keyword::STORAGE => CreateTableLikeProperty::Storage, - unexpected_keyword => return Err(ParserError::ParserError(format!( - "Internal parser error: unexpected LIKE option {unexpected_keyword:?}" - ))), + other => { + return Err(ParserError::ParserError(format!( + "Internal parser error: unexpected LIKE option {other:?}" + ))) + } }; options.push(if keyword == Keyword::INCLUDING { CreateTableLikeOption::Including(property)
diff --git a/tests/sqlparser_common.rs b/tests/sqlparser_common.rs index 28057ca..2a3029a 100644 --- a/tests/sqlparser_common.rs +++ b/tests/sqlparser_common.rs
@@ -20345,6 +20345,12 @@ } _ => unreachable!(), } + assert_eq!( + all_dialects_except(|d| d.supports_create_table_like_parenthesized()) + .parse_sql_statements("CREATE TABLE new LIKE") + .unwrap_err(), + ParserError::ParserError("Expected: identifier, found: EOF".to_string()) + ); } #[test]
diff --git a/tests/sqlparser_postgres.rs b/tests/sqlparser_postgres.rs index 4f87343..1d9300c 100644 --- a/tests/sqlparser_postgres.rs +++ b/tests/sqlparser_postgres.rs
@@ -14410,4 +14410,32 @@ .unwrap_err(), ParserError::ParserError("Expected: ), found: COMMENTS".to_string()) ); + assert_eq!( + pg().parse_sql_statements("CREATE TABLE new (LIKE)") + .unwrap_err(), + ParserError::ParserError("Expected: identifier, found: )".to_string()) + ); +} + +#[test] +fn display_create_table_like_propagates_write_errors() { + use core::fmt::{self, Write}; + + struct RejectingWriter(&'static str); + + impl Write for RejectingWriter { + fn write_str(&mut self, value: &str) -> fmt::Result { + if value.contains(self.0) { + Err(fmt::Error) + } else { + Ok(()) + } + } + } + + let statement = pg().verified_stmt("CREATE TABLE new (LIKE old INCLUDING ALL)"); + for rejected in ["LIKE", "INCLUDING", "ALL"] { + let mut writer = RejectingWriter(rejected); + assert_eq!(write!(writer, "{statement}"), Err(fmt::Error), "{rejected}"); + } }