mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-11-01 23:50:56 +00:00
Support Modify Column for MySQL dialect (#1216)
This commit is contained in:
parent
4604628c43
commit
7b49c69b3a
4 changed files with 135 additions and 0 deletions
|
|
@ -134,6 +134,14 @@ pub enum AlterTableOperation {
|
|||
/// MySQL `ALTER TABLE` only [FIRST | AFTER column_name]
|
||||
column_position: Option<MySQLColumnPosition>,
|
||||
},
|
||||
// CHANGE [ COLUMN ] <col_name> <data_type> [ <options> ]
|
||||
ModifyColumn {
|
||||
col_name: Ident,
|
||||
data_type: DataType,
|
||||
options: Vec<ColumnOption>,
|
||||
/// MySQL `ALTER TABLE` only [FIRST | AFTER column_name]
|
||||
column_position: Option<MySQLColumnPosition>,
|
||||
},
|
||||
/// `RENAME CONSTRAINT <old_constraint_name> TO <new_constraint_name>`
|
||||
///
|
||||
/// Note: this is a PostgreSQL-specific operation.
|
||||
|
|
@ -292,6 +300,22 @@ impl fmt::Display for AlterTableOperation {
|
|||
|
||||
Ok(())
|
||||
}
|
||||
AlterTableOperation::ModifyColumn {
|
||||
col_name,
|
||||
data_type,
|
||||
options,
|
||||
column_position,
|
||||
} => {
|
||||
write!(f, "MODIFY COLUMN {col_name} {data_type}")?;
|
||||
if !options.is_empty() {
|
||||
write!(f, " {}", display_separated(options, " "))?;
|
||||
}
|
||||
if let Some(position) = column_position {
|
||||
write!(f, " {position}")?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
AlterTableOperation::RenameConstraint { old_name, new_name } => {
|
||||
write!(f, "RENAME CONSTRAINT {old_name} TO {new_name}")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -438,6 +438,7 @@ define_keywords!(
|
|||
MOD,
|
||||
MODE,
|
||||
MODIFIES,
|
||||
MODIFY,
|
||||
MODULE,
|
||||
MONTH,
|
||||
MSCK,
|
||||
|
|
|
|||
|
|
@ -5757,6 +5757,23 @@ impl<'a> Parser<'a> {
|
|||
options,
|
||||
column_position,
|
||||
}
|
||||
} else if self.parse_keyword(Keyword::MODIFY) {
|
||||
let _ = self.parse_keyword(Keyword::COLUMN); // [ COLUMN ]
|
||||
let col_name = self.parse_identifier(false)?;
|
||||
let data_type = self.parse_data_type()?;
|
||||
let mut options = vec![];
|
||||
while let Some(option) = self.parse_optional_column_option()? {
|
||||
options.push(option);
|
||||
}
|
||||
|
||||
let column_position = self.parse_column_position()?;
|
||||
|
||||
AlterTableOperation::ModifyColumn {
|
||||
col_name,
|
||||
data_type,
|
||||
options,
|
||||
column_position,
|
||||
}
|
||||
} else if self.parse_keyword(Keyword::ALTER) {
|
||||
let _ = self.parse_keyword(Keyword::COLUMN); // [ COLUMN ]
|
||||
let column_name = self.parse_identifier(false)?;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue