Skip to content

Commit 74643f9

Browse files
committed
more rusty
1 parent 6dd0130 commit 74643f9

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

src/parser/mod.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -548,9 +548,7 @@ impl<'a> Parser<'a> {
548548
Keyword::PRAGMA => self.parse_pragma(),
549549
Keyword::UNLOAD => self.parse_unload(),
550550
// `RENAME TABLE` is mysql specific https://dev.mysql.com/doc/refman/9.1/en/rename-table.html
551-
Keyword::RENAME if self.dialect.supports_rename_table() => {
552-
self.parse_rename_table()
553-
}
551+
Keyword::RENAME => self.parse_rename(),
554552
// `INSTALL` is duckdb specific https://duckdb.org/docs/extensions/overview
555553
Keyword::INSTALL if dialect_of!(self is DuckDbDialect | GenericDialect) => {
556554
self.parse_install()
@@ -1048,10 +1046,14 @@ impl<'a> Parser<'a> {
10481046
Ok(Statement::NOTIFY { channel, payload })
10491047
}
10501048

1051-
pub fn parse_rename_table(&mut self) -> Result<Statement, ParserError> {
1052-
self.expect_keyword(Keyword::TABLE)?;
1053-
let operations = self.parse_comma_separated(Parser::parse_rename_object_def)?;
1054-
Ok(Statement::RenameTable { operations })
1049+
pub fn parse_rename(&mut self) -> Result<Statement, ParserError> {
1050+
if self.dialect.supports_rename_table() && self.peek_keyword(Keyword::TABLE) {
1051+
self.expect_keyword(Keyword::TABLE)?;
1052+
let operations = self.parse_comma_separated(Parser::parse_rename_object_def)?;
1053+
Ok(Statement::RenameTable { operations })
1054+
} else {
1055+
self.expected("an object type after RENAME", self.peek_token())
1056+
}
10551057
}
10561058

10571059
// Tries to parse an expression by matching the specified word to known keywords that have a special meaning in the dialect.

tests/sqlparser_common.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4121,13 +4121,22 @@ fn parse_rename_table() {
41214121
ParserError::ParserError("Expected: end of statement, found: a".to_string())
41224122
);
41234123

4124+
assert_eq!(
4125+
dialects
4126+
.parse_sql_statements("RENAME TABLE1 `old_table` TO new_table a")
4127+
.unwrap_err(),
4128+
ParserError::ParserError(
4129+
"Expected: an object type after RENAME, found: TABLE1".to_string()
4130+
)
4131+
);
4132+
41244133
let dialects = all_dialects_where(|d| !d.supports_rename_table());
41254134

41264135
assert_eq!(
41274136
dialects
41284137
.parse_sql_statements("RENAME TABLE `old_table` TO new_table")
41294138
.unwrap_err(),
4130-
ParserError::ParserError("Expected: an SQL statement, found: RENAME".to_string())
4139+
ParserError::ParserError("Expected: an object type after RENAME, found: TABLE".to_string())
41314140
);
41324141
}
41334142

0 commit comments

Comments
 (0)