mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-12-23 11:12:51 +00:00
Add support for INSERT INTO VALUE (#2085)
Some checks are pending
license / Release Audit Tool (RAT) (push) Waiting to run
Rust / codestyle (push) Waiting to run
Rust / lint (push) Waiting to run
Rust / benchmark-lint (push) Waiting to run
Rust / compile (push) Waiting to run
Rust / docs (push) Waiting to run
Rust / compile-no-std (push) Waiting to run
Rust / test (beta) (push) Waiting to run
Rust / test (nightly) (push) Waiting to run
Rust / test (stable) (push) Waiting to run
Some checks are pending
license / Release Audit Tool (RAT) (push) Waiting to run
Rust / codestyle (push) Waiting to run
Rust / lint (push) Waiting to run
Rust / benchmark-lint (push) Waiting to run
Rust / compile (push) Waiting to run
Rust / docs (push) Waiting to run
Rust / compile-no-std (push) Waiting to run
Rust / test (beta) (push) Waiting to run
Rust / test (nightly) (push) Waiting to run
Rust / test (stable) (push) Waiting to run
This commit is contained in:
parent
c439ee9419
commit
f69407b344
8 changed files with 64 additions and 13 deletions
|
|
@ -3135,12 +3135,18 @@ pub struct Values {
|
|||
/// Was there an explicit ROWs keyword (MySQL)?
|
||||
/// <https://dev.mysql.com/doc/refman/8.0/en/values.html>
|
||||
pub explicit_row: bool,
|
||||
// MySql supports both VALUES and VALUE keywords.
|
||||
// <https://dev.mysql.com/doc/refman/9.2/en/insert.html>
|
||||
pub value_keyword: bool,
|
||||
pub rows: Vec<Vec<Expr>>,
|
||||
}
|
||||
|
||||
impl fmt::Display for Values {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
f.write_str("VALUES")?;
|
||||
match self.value_keyword {
|
||||
true => f.write_str("VALUE")?,
|
||||
false => f.write_str("VALUES")?,
|
||||
};
|
||||
let prefix = if self.explicit_row { "ROW" } else { "" };
|
||||
let mut delim = "";
|
||||
for row in &self.rows {
|
||||
|
|
|
|||
|
|
@ -223,6 +223,7 @@ impl Spanned for Values {
|
|||
fn span(&self) -> Span {
|
||||
let Values {
|
||||
explicit_row: _, // bool,
|
||||
value_keyword: _,
|
||||
rows,
|
||||
} = self;
|
||||
|
||||
|
|
|
|||
|
|
@ -12533,7 +12533,10 @@ impl<'a> Parser<'a> {
|
|||
SetExpr::Query(subquery)
|
||||
} else if self.parse_keyword(Keyword::VALUES) {
|
||||
let is_mysql = dialect_of!(self is MySqlDialect);
|
||||
SetExpr::Values(self.parse_values(is_mysql)?)
|
||||
SetExpr::Values(self.parse_values(is_mysql, false)?)
|
||||
} else if self.parse_keyword(Keyword::VALUE) {
|
||||
let is_mysql = dialect_of!(self is MySqlDialect);
|
||||
SetExpr::Values(self.parse_values(is_mysql, true)?)
|
||||
} else if self.parse_keyword(Keyword::TABLE) {
|
||||
SetExpr::Table(Box::new(self.parse_as_table()?))
|
||||
} else {
|
||||
|
|
@ -13837,7 +13840,7 @@ impl<'a> Parser<'a> {
|
|||
// Snowflake and Databricks allow syntax like below:
|
||||
// SELECT * FROM VALUES (1, 'a'), (2, 'b') AS t (col1, col2)
|
||||
// where there are no parentheses around the VALUES clause.
|
||||
let values = SetExpr::Values(self.parse_values(false)?);
|
||||
let values = SetExpr::Values(self.parse_values(false, false)?);
|
||||
let alias = self.maybe_parse_table_alias()?;
|
||||
Ok(TableFactor::Derived {
|
||||
lateral: false,
|
||||
|
|
@ -16504,7 +16507,11 @@ impl<'a> Parser<'a> {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn parse_values(&mut self, allow_empty: bool) -> Result<Values, ParserError> {
|
||||
pub fn parse_values(
|
||||
&mut self,
|
||||
allow_empty: bool,
|
||||
value_keyword: bool,
|
||||
) -> Result<Values, ParserError> {
|
||||
let mut explicit_row = false;
|
||||
|
||||
let rows = self.parse_comma_separated(|parser| {
|
||||
|
|
@ -16522,7 +16529,11 @@ impl<'a> Parser<'a> {
|
|||
Ok(exprs)
|
||||
}
|
||||
})?;
|
||||
Ok(Values { explicit_row, rows })
|
||||
Ok(Values {
|
||||
explicit_row,
|
||||
rows,
|
||||
value_keyword,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn parse_start_transaction(&mut self) -> Result<Statement, ParserError> {
|
||||
|
|
@ -16937,7 +16948,7 @@ impl<'a> Parser<'a> {
|
|||
MergeInsertKind::Row
|
||||
} else {
|
||||
self.expect_keyword_is(Keyword::VALUES)?;
|
||||
let values = self.parse_values(is_mysql)?;
|
||||
let values = self.parse_values(is_mysql, false)?;
|
||||
MergeInsertKind::Values(values)
|
||||
};
|
||||
MergeAction::Insert(MergeInsertExpr { columns, kind })
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue