Skip to content

Commit 1fa7d43

Browse files
mvzinkayman-sigma
authored andcommitted
MySQL: Support comma-separated CREATE TABLE options (apache#1989)
1 parent 8bf11a1 commit 1fa7d43

3 files changed

Lines changed: 11 additions & 1 deletion

File tree

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
@@ -7739,6 +7739,9 @@ impl<'a> Parser<'a> {
77397739

77407740
while let Some(option) = self.parse_plain_option()? {
77417741
options.push(option);
7742+
// Some dialects support comma-separated options; it shouldn't introduce ambiguity to
7743+
// consume it for all dialects.
7744+
let _ = self.consume_token(&Token::Comma);
77427745
}
77437746

77447747
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)