mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-10-11 06:22:04 +00:00
Support row_alias
and col_aliases
in INSERT
statement for mysql and generic dialects (#1136)
This commit is contained in:
parent
5da66adda9
commit
11899fd0cb
4 changed files with 148 additions and 4 deletions
|
@ -1759,6 +1759,8 @@ pub enum Statement {
|
|||
replace_into: bool,
|
||||
/// Only for mysql
|
||||
priority: Option<MysqlInsertPriority>,
|
||||
/// Only for mysql
|
||||
insert_alias: Option<InsertAliases>,
|
||||
},
|
||||
/// ```sql
|
||||
/// INSTALL
|
||||
|
@ -2773,6 +2775,7 @@ impl fmt::Display for Statement {
|
|||
returning,
|
||||
replace_into,
|
||||
priority,
|
||||
insert_alias,
|
||||
} => {
|
||||
let table_name = if let Some(alias) = table_alias {
|
||||
format!("{table_name} AS {alias}")
|
||||
|
@ -2822,6 +2825,16 @@ impl fmt::Display for Statement {
|
|||
write!(f, "DEFAULT VALUES")?;
|
||||
}
|
||||
|
||||
if let Some(insert_alias) = insert_alias {
|
||||
write!(f, " AS {0}", insert_alias.row_alias)?;
|
||||
|
||||
if let Some(col_aliases) = &insert_alias.col_aliases {
|
||||
if !col_aliases.is_empty() {
|
||||
write!(f, " ({})", display_comma_separated(col_aliases))?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(on) = on {
|
||||
write!(f, "{on}")?;
|
||||
}
|
||||
|
@ -4194,6 +4207,14 @@ pub enum OnInsert {
|
|||
OnConflict(OnConflict),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
|
||||
pub struct InsertAliases {
|
||||
pub row_alias: ObjectName,
|
||||
pub col_aliases: Option<Vec<Ident>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue