mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-09-27 07:59:11 +00:00
Support CREATE TABLE ON UPDATE <expr>
Function (#685)
* feat : OnUpdate Function Implement * feat : add GenericDialect Options
This commit is contained in:
parent
b1a000f149
commit
3e990466f8
3 changed files with 13 additions and 8 deletions
|
@ -558,6 +558,7 @@ pub enum ColumnOption {
|
||||||
DialectSpecific(Vec<Token>),
|
DialectSpecific(Vec<Token>),
|
||||||
CharacterSet(ObjectName),
|
CharacterSet(ObjectName),
|
||||||
Comment(String),
|
Comment(String),
|
||||||
|
OnUpdate(Expr),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for ColumnOption {
|
impl fmt::Display for ColumnOption {
|
||||||
|
@ -592,6 +593,7 @@ impl fmt::Display for ColumnOption {
|
||||||
DialectSpecific(val) => write!(f, "{}", display_separated(val, " ")),
|
DialectSpecific(val) => write!(f, "{}", display_separated(val, " ")),
|
||||||
CharacterSet(n) => write!(f, "CHARACTER SET {}", n),
|
CharacterSet(n) => write!(f, "CHARACTER SET {}", n),
|
||||||
Comment(v) => write!(f, "COMMENT '{}'", escape_single_quote_string(v)),
|
Comment(v) => write!(f, "COMMENT '{}'", escape_single_quote_string(v)),
|
||||||
|
OnUpdate(expr) => write!(f, "ON UPDATE {}", expr),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3474,11 +3474,10 @@ impl<'a> Parser<'a> {
|
||||||
Token::make_keyword("AUTOINCREMENT"),
|
Token::make_keyword("AUTOINCREMENT"),
|
||||||
])))
|
])))
|
||||||
} else if self.parse_keywords(&[Keyword::ON, Keyword::UPDATE])
|
} else if self.parse_keywords(&[Keyword::ON, Keyword::UPDATE])
|
||||||
&& dialect_of!(self is MySqlDialect)
|
&& dialect_of!(self is MySqlDialect | GenericDialect)
|
||||||
{
|
{
|
||||||
Ok(Some(ColumnOption::DialectSpecific(vec![
|
let expr = self.parse_expr()?;
|
||||||
Token::make_keyword("ON UPDATE"),
|
Ok(Some(ColumnOption::OnUpdate(expr)))
|
||||||
])))
|
|
||||||
} else {
|
} else {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1031,7 +1031,7 @@ fn parse_kill() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_table_colum_option_on_update() {
|
fn parse_table_colum_option_on_update() {
|
||||||
let sql1 = "CREATE TABLE foo (`modification_time` DATETIME ON UPDATE)";
|
let sql1 = "CREATE TABLE foo (`modification_time` DATETIME ON UPDATE CURRENT_TIMESTAMP())";
|
||||||
match mysql().verified_stmt(sql1) {
|
match mysql().verified_stmt(sql1) {
|
||||||
Statement::CreateTable { name, columns, .. } => {
|
Statement::CreateTable { name, columns, .. } => {
|
||||||
assert_eq!(name.to_string(), "foo");
|
assert_eq!(name.to_string(), "foo");
|
||||||
|
@ -1042,9 +1042,13 @@ fn parse_table_colum_option_on_update() {
|
||||||
collation: None,
|
collation: None,
|
||||||
options: vec![ColumnOptionDef {
|
options: vec![ColumnOptionDef {
|
||||||
name: None,
|
name: None,
|
||||||
option: ColumnOption::DialectSpecific(vec![Token::make_keyword(
|
option: ColumnOption::OnUpdate(Expr::Function(Function {
|
||||||
"ON UPDATE"
|
name: ObjectName(vec![Ident::new("CURRENT_TIMESTAMP")]),
|
||||||
)]),
|
args: vec![],
|
||||||
|
over: None,
|
||||||
|
distinct: false,
|
||||||
|
special: false,
|
||||||
|
})),
|
||||||
},],
|
},],
|
||||||
}],
|
}],
|
||||||
columns
|
columns
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue