Reject TEMPORARY, PURGE and ON in DROP FOREIGN TABLE
diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 63221cf..7dc92d2 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs
@@ -8169,6 +8169,12 @@ } else { None }; + if object_type == ObjectType::ForeignTable && (temporary || purge || table.is_some()) { + return parser_err!( + "Cannot specify TEMPORARY, PURGE, or ON in DROP FOREIGN TABLE", + loc + ); + } Ok(Statement::Drop { object_type, if_exists,
diff --git a/tests/sqlparser_postgres.rs b/tests/sqlparser_postgres.rs index 552e67a..e2d0214 100644 --- a/tests/sqlparser_postgres.rs +++ b/tests/sqlparser_postgres.rs
@@ -11263,3 +11263,29 @@ "sql parser error: Expected: identifier, found: EOF" ); } + +#[test] +fn parse_drop_foreign_table_rejects_modifiers() { + for sql in [ + "DROP TEMPORARY FOREIGN TABLE ft", + "DROP FOREIGN TABLE ft PURGE", + "DROP FOREIGN TABLE ft ON t", + ] { + for dialect in all_dialects().dialects { + assert!( + Parser::parse_sql(dialect.as_ref(), sql).is_err(), + "{sql} with {dialect:?}" + ); + } + } + for sql in ["DROP FOREIGN TABLE ft PURGE", "DROP FOREIGN TABLE ft ON t"] { + assert_eq!( + pg_and_generic() + .parse_sql_statements(sql) + .unwrap_err() + .to_string(), + "sql parser error: Cannot specify TEMPORARY, PURGE, or ON in DROP FOREIGN TABLE", + "{sql}" + ); + } +}