apache / datafusion-sqlparser-rs

Extensible SQL Lexer and Parser for Rust
Apache License 2.0
2.8k stars 543 forks source link

MySQL's `CREATE TABLE ... SELECT` syntax #1509

Open lovasoa opened 1 week ago

lovasoa commented 1 week ago

SQLite, Postgres, MsSQL and MySQL all support the CREATE TABLE table_name(columns) AS SELECT ....

However, MySQL (and Mariadb) allow omitting the AS keyword, and specifying a table like

CREATE TABLE bar (m INT) SELECT n FROM foo;

Currently, sqlparser parses this as two distinct statements: a create table followed by a select. Instead, it should parse it the same as

CREATE TABLE bar (m INT) AS SELECT n FROM foo;

https://dev.mysql.com/doc/refman/8.4/en/create-table-select.html