mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-09-02 12:17:21 +00:00
Support arbitrary INSERT sources
INSERT takes arbitrary queries as sources, not just VALUES clauses. For example, `INSERT INTO foo SELECT * FROM bar` is perfectly valid.
This commit is contained in:
parent
9420070a0d
commit
14e07ebdda
3 changed files with 17 additions and 11 deletions
|
@ -342,8 +342,8 @@ pub enum SQLStatement {
|
|||
table_name: SQLObjectName,
|
||||
/// COLUMNS
|
||||
columns: Vec<SQLIdent>,
|
||||
/// VALUES (vector of rows to insert)
|
||||
values: SQLValues,
|
||||
/// A SQL query that specifies what to insert
|
||||
source: Box<SQLQuery>,
|
||||
},
|
||||
SQLCopy {
|
||||
/// TABLE
|
||||
|
@ -409,13 +409,13 @@ impl ToString for SQLStatement {
|
|||
SQLStatement::SQLInsert {
|
||||
table_name,
|
||||
columns,
|
||||
values,
|
||||
source,
|
||||
} => {
|
||||
let mut s = format!("INSERT INTO {}", table_name.to_string());
|
||||
let mut s = format!("INSERT INTO {} ", table_name.to_string());
|
||||
if !columns.is_empty() {
|
||||
s += &format!(" ({})", columns.join(", "));
|
||||
s += &format!("({}) ", columns.join(", "));
|
||||
}
|
||||
s += &format!(" {}", values.to_string());
|
||||
s += &source.to_string();
|
||||
s
|
||||
}
|
||||
SQLStatement::SQLCopy {
|
||||
|
|
|
@ -1565,12 +1565,11 @@ impl Parser {
|
|||
self.expect_keyword("INTO")?;
|
||||
let table_name = self.parse_object_name()?;
|
||||
let columns = self.parse_parenthesized_column_list(Optional)?;
|
||||
self.expect_keyword("VALUES")?;
|
||||
let values = self.parse_values()?;
|
||||
let source = Box::new(self.parse_query()?);
|
||||
Ok(SQLStatement::SQLInsert {
|
||||
table_name,
|
||||
columns,
|
||||
values,
|
||||
source,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue