mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-10-16 16:59:02 +00:00
Support SQLite column definitions with no type (#1075)
This commit is contained in:
parent
a75778c8c7
commit
a430d1a5a7
6 changed files with 51 additions and 3 deletions
|
@ -4272,7 +4272,11 @@ impl<'a> Parser<'a> {
|
|||
|
||||
pub fn parse_column_def(&mut self) -> Result<ColumnDef, ParserError> {
|
||||
let name = self.parse_identifier()?;
|
||||
let data_type = self.parse_data_type()?;
|
||||
let data_type = if self.is_column_type_sqlite_unspecified() {
|
||||
DataType::Unspecified
|
||||
} else {
|
||||
self.parse_data_type()?
|
||||
};
|
||||
let mut collation = if self.parse_keyword(Keyword::COLLATE) {
|
||||
Some(self.parse_object_name()?)
|
||||
} else {
|
||||
|
@ -4308,6 +4312,29 @@ impl<'a> Parser<'a> {
|
|||
})
|
||||
}
|
||||
|
||||
fn is_column_type_sqlite_unspecified(&mut self) -> bool {
|
||||
if dialect_of!(self is SQLiteDialect) {
|
||||
match self.peek_token().token {
|
||||
Token::Word(word) => matches!(
|
||||
word.keyword,
|
||||
Keyword::CONSTRAINT
|
||||
| Keyword::PRIMARY
|
||||
| Keyword::NOT
|
||||
| Keyword::UNIQUE
|
||||
| Keyword::CHECK
|
||||
| Keyword::DEFAULT
|
||||
| Keyword::COLLATE
|
||||
| Keyword::REFERENCES
|
||||
| Keyword::GENERATED
|
||||
| Keyword::AS
|
||||
),
|
||||
_ => true, // e.g. comma immediately after column name
|
||||
}
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parse_optional_column_option(&mut self) -> Result<Option<ColumnOption>, ParserError> {
|
||||
if self.parse_keywords(&[Keyword::CHARACTER, Keyword::SET]) {
|
||||
Ok(Some(ColumnOption::CharacterSet(self.parse_object_name()?)))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue