iffyio commented on code in PR #2148:
URL:
https://github.com/apache/datafusion-sqlparser-rs/pull/2148#discussion_r2741691934
##########
src/ast/dml.rs:
##########
@@ -90,92 +90,174 @@ pub struct Insert {
///
/// [ClickHouse formats JSON
insert](https://clickhouse.com/docs/en/interfaces/formats#json-inserting-data)
pub format_clause: Option<InputFormatClause>,
+ /// For multi-table insert: `INSERT FIRST` vs `INSERT ALL`
+ ///
+ /// When `true`, this is an `INSERT FIRST` statement (only the first
matching WHEN clause is executed).
+ /// When `false` with non-empty `clauses`, this is an `INSERT ALL`
statement.
+ ///
+ /// See:
<https://docs.snowflake.com/en/sql-reference/sql/insert-multi-table>
+ pub insert_first: bool,
+ /// For multi-table insert: additional INTO clauses (unconditional)
+ ///
+ /// Used for `INSERT ALL INTO t1 INTO t2 ... SELECT ...`
+ ///
+ /// See:
<https://docs.snowflake.com/en/sql-reference/sql/insert-multi-table>
+ pub multi_table_into_clauses: Vec<MultiTableInsertIntoClause>,
+ /// For conditional multi-table insert: WHEN clauses
+ ///
+ /// Used for `INSERT ALL/FIRST WHEN cond THEN INTO t1 ... SELECT ...`
+ ///
+ /// See:
<https://docs.snowflake.com/en/sql-reference/sql/insert-multi-table>
+ pub multi_table_when_clauses: Vec<MultiTableInsertWhenClause>,
+ /// For conditional multi-table insert: ELSE clause
+ ///
+ /// See:
<https://docs.snowflake.com/en/sql-reference/sql/insert-multi-table>
+ pub multi_table_else_clause: Option<Vec<MultiTableInsertIntoClause>>,
}
impl Display for Insert {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- let table_name = if let Some(alias) = &self.table_alias {
- format!("{0} AS {alias}", self.table)
- } else {
- self.table.to_string()
- };
+ // Check if this is a Snowflake multi-table insert
+ let is_multi_table = !self.multi_table_into_clauses.is_empty()
+ || !self.multi_table_when_clauses.is_empty();
Review Comment:
Oh so here's an example to clarify what I meant in the previous comment. If
we take this block in the display logic
```rust
if !is_multi_table {
let table_name = if let Some(alias) = &self.table_alias {
format!("{0} AS {alias}", self.table)
} else {
self.table.to_string()
};
write!(f, " {table_name} ")?;
}
```
if we change it to the following - removing the `if` condition:
```rust
let table_name = if let Some(alias) = &self.table_alias {
format!("{0} AS {alias}", self.table)
} else {
self.table.to_string()
};
write!(f, " {table_name} ")?;
```
what would be the effect (is the function display still correct)? Its
unclear to me if/why the `is_multi_table` flag/condition is needed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]