Support for IF NOT EXISTS in ALTER TABLE ADD COLUMN (#707)

This commit is contained in:
Augusto Fotino 2022-11-29 17:37:14 -03:00 committed by GitHub
parent bae682255d
commit 886875f3bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 110 additions and 11 deletions

View file

@ -3205,9 +3205,22 @@ impl<'a> Parser<'a> {
new_partitions: partitions,
}
} else {
let _ = self.parse_keyword(Keyword::COLUMN);
let column_keyword = self.parse_keyword(Keyword::COLUMN);
let if_not_exists = if dialect_of!(self is PostgreSqlDialect | BigQueryDialect | GenericDialect)
{
self.parse_keywords(&[Keyword::IF, Keyword::NOT, Keyword::EXISTS])
|| if_not_exists
} else {
false
};
let column_def = self.parse_column_def()?;
AlterTableOperation::AddColumn { column_def }
AlterTableOperation::AddColumn {
column_keyword,
if_not_exists,
column_def,
}
}
}
} else if self.parse_keyword(Keyword::RENAME) {
@ -5858,7 +5871,6 @@ mod tests {
#[cfg(test)]
mod test_parse_data_type {
use crate::ast::{
CharLengthUnits, CharacterLength, DataType, ExactNumberInfo, ObjectName, TimezoneInfo,
};