mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-10-29 22:37:17 +00:00
Add SQLite "ON CONFLICT" column option in CREATE TABLE statements (#1442)
Co-authored-by: hulk <hulk.website@gmail.com> Co-authored-by: Ifeanyi Ubah <ify1992@yahoo.com>
This commit is contained in:
parent
84348d483e
commit
8badcdc200
3 changed files with 62 additions and 0 deletions
|
|
@ -33,6 +33,7 @@ use crate::ast::{
|
|||
display_comma_separated, display_separated, DataType, Expr, Ident, MySQLColumnPosition,
|
||||
ObjectName, OrderByExpr, ProjectionSelect, SequenceOptions, SqlOption, Value,
|
||||
};
|
||||
use crate::keywords::Keyword;
|
||||
use crate::tokenizer::Token;
|
||||
|
||||
/// An `ALTER TABLE` (`Statement::AlterTable`) operation
|
||||
|
|
@ -1186,6 +1187,9 @@ pub enum ColumnOption {
|
|||
/// ```
|
||||
/// [MS SQL Server]: https://learn.microsoft.com/en-us/sql/t-sql/statements/create-table-transact-sql-identity-property
|
||||
Identity(Option<IdentityProperty>),
|
||||
/// SQLite specific: ON CONFLICT option on column definition
|
||||
/// <https://www.sqlite.org/lang_conflict.html>
|
||||
OnConflict(Keyword),
|
||||
}
|
||||
|
||||
impl fmt::Display for ColumnOption {
|
||||
|
|
@ -1294,6 +1298,10 @@ impl fmt::Display for ColumnOption {
|
|||
}
|
||||
Ok(())
|
||||
}
|
||||
OnConflict(keyword) => {
|
||||
write!(f, "ON CONFLICT {:?}", keyword)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6224,6 +6224,19 @@ impl<'a> Parser<'a> {
|
|||
None
|
||||
};
|
||||
Ok(Some(ColumnOption::Identity(property)))
|
||||
} else if dialect_of!(self is SQLiteDialect | GenericDialect)
|
||||
&& self.parse_keywords(&[Keyword::ON, Keyword::CONFLICT])
|
||||
{
|
||||
// Support ON CONFLICT for SQLite
|
||||
Ok(Some(ColumnOption::OnConflict(
|
||||
self.expect_one_of_keywords(&[
|
||||
Keyword::ROLLBACK,
|
||||
Keyword::ABORT,
|
||||
Keyword::FAIL,
|
||||
Keyword::IGNORE,
|
||||
Keyword::REPLACE,
|
||||
])?,
|
||||
)))
|
||||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue