Skip to content

Commit 7bc4351

Browse files
committed
MySQL: Support comma-separated CREATE TABLE options
In [MySQL], options for `CREATE TABLE` following the body can be optionally separated by commas. I'm not aware of any cases where this affects parsing (e.g. eliminating ambiguity or anything), so we just optionally eat comma tokens after each option is parsed. [MySQL]: https://dev.mysql.com/doc/refman/8.4/en/create-table.html
1 parent c1648e7 commit 7bc4351

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

src/dialect/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ pub trait Dialect: Debug + Any {
590590
false
591591
}
592592

593-
/// Returne true if the dialect supports specifying multiple options
593+
/// Return true if the dialect supports specifying multiple options
594594
/// in a `CREATE TABLE` statement for the structure of the new table. For example:
595595
/// `CREATE TABLE t (a INT, b INT) AS SELECT 1 AS b, 2 AS a`
596596
fn supports_create_table_multi_schema_info_sources(&self) -> bool {

src/parser/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7708,6 +7708,9 @@ impl<'a> Parser<'a> {
77087708

77097709
while let Some(option) = self.parse_plain_option()? {
77107710
options.push(option);
7711+
// Some dialects support comma-separated options; it shouldn't introduce ambiguity to
7712+
// consume it for all dialects.
7713+
let _ = self.consume_token(&Token::Comma);
77117714
}
77127715

77137716
Ok(options)

tests/sqlparser_mysql.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,6 +1361,13 @@ fn parse_create_table_gencol() {
13611361
mysql_and_generic().verified_stmt("CREATE TABLE t1 (a INT, b INT AS (a * 2) STORED)");
13621362
}
13631363

1364+
#[test]
1365+
fn parse_create_table_options_comma_separated() {
1366+
let sql = "CREATE TABLE t (x INT) DEFAULT CHARSET = utf8mb4, ENGINE = InnoDB , AUTO_INCREMENT 1 DATA DIRECTORY '/var/lib/mysql/data'";
1367+
let canonical = "CREATE TABLE t (x INT) DEFAULT CHARSET = utf8mb4 ENGINE = InnoDB AUTO_INCREMENT = 1 DATA DIRECTORY = '/var/lib/mysql/data'";
1368+
mysql_and_generic().one_statement_parses_to(sql, canonical);
1369+
}
1370+
13641371
#[test]
13651372
fn parse_quote_identifiers() {
13661373
let sql = "CREATE TABLE `PRIMARY` (`BEGIN` INT PRIMARY KEY)";

0 commit comments

Comments
 (0)