mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-30 18:57:21 +00:00
Add CREATE TABLE AS support (#206)
We parse it as a regular `CREATE TABLE` statement
followed by an `AS <query>`, which is how BigQuery works:
https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language#create_table_statement
ANSI SQL and PostgreSQL only support a plain list of columns
after the table name in a CTAS
`CREATE TABLE t (a) AS SELECT a FROM foo`
We currently only allow specifying a full schema with data
types, or omitting it altogether.
https://www.postgresql.org/docs/12/sql-createtableas.html
https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#as-subquery-clause
Finally, when no schema is specified, we print empty parens after a
plain `CREATE TABLE t ();` as required by PostgreSQL, but skip them
in a CTAS: `CREATE TABLE t AS ...`. This affects serialization only,
the parser allows omitting the schema in a regular `CREATE TABLE` too
since the first release of the parser:
7d27abdfb4/src/sqlparser.rs (L325-L332)
Co-authored-by: Nickolay Ponomarev <asqueella@gmail.com>
This commit is contained in:
parent
26361fd854
commit
15d5f71646
6 changed files with 104 additions and 26 deletions
|
@ -77,7 +77,7 @@ fn parse_show_columns() {
|
|||
Statement::ShowColumns {
|
||||
extended: false,
|
||||
full: false,
|
||||
table_name: table_name,
|
||||
table_name,
|
||||
filter: Some(ShowStatementFilter::Where(
|
||||
mysql_and_generic().verified_expr("1 = 2")
|
||||
)),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue