MS SQL Server: add support for IDENTITY column option (#1432)

This commit is contained in:
Aleksei Piianin 2024-09-20 18:44:24 +02:00 committed by GitHub
parent 71318df8b9
commit fb42425d51
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 155 additions and 2 deletions

View file

@ -908,6 +908,117 @@ fn parse_create_table_with_invalid_options() {
}
}
#[test]
fn parse_create_table_with_identity_column() {
let with_column_options = [
(
r#"CREATE TABLE mytable (columnA INT IDENTITY NOT NULL)"#,
vec![
ColumnOptionDef {
name: None,
option: ColumnOption::Identity(None),
},
ColumnOptionDef {
name: None,
option: ColumnOption::NotNull,
},
],
),
(
r#"CREATE TABLE mytable (columnA INT IDENTITY(1, 1) NOT NULL)"#,
vec![
ColumnOptionDef {
name: None,
#[cfg(not(feature = "bigdecimal"))]
option: ColumnOption::Identity(Some(IdentityProperty {
seed: Expr::Value(Value::Number("1".to_string(), false)),
increment: Expr::Value(Value::Number("1".to_string(), false)),
})),
#[cfg(feature = "bigdecimal")]
option: ColumnOption::Identity(Some(IdentityProperty {
seed: Expr::Value(Value::Number(bigdecimal::BigDecimal::from(1), false)),
increment: Expr::Value(Value::Number(
bigdecimal::BigDecimal::from(1),
false,
)),
})),
},
ColumnOptionDef {
name: None,
option: ColumnOption::NotNull,
},
],
),
];
for (sql, column_options) in with_column_options {
assert_eq!(
ms_and_generic().verified_stmt(sql),
Statement::CreateTable(CreateTable {
or_replace: false,
temporary: false,
external: false,
global: None,
if_not_exists: false,
transient: false,
volatile: false,
name: ObjectName(vec![Ident {
value: "mytable".to_string(),
quote_style: None,
},],),
columns: vec![ColumnDef {
name: Ident {
value: "columnA".to_string(),
quote_style: None,
},
data_type: Int(None,),
collation: None,
options: column_options,
},],
constraints: vec![],
hive_distribution: HiveDistributionStyle::NONE,
hive_formats: Some(HiveFormat {
row_format: None,
serde_properties: None,
storage: None,
location: None,
},),
table_properties: vec![],
with_options: vec![],
file_format: None,
location: None,
query: None,
without_rowid: false,
like: None,
clone: None,
engine: None,
comment: None,
auto_increment_offset: None,
default_charset: None,
collation: None,
on_commit: None,
on_cluster: None,
primary_key: None,
order_by: None,
partition_by: None,
cluster_by: None,
clustered_by: None,
options: None,
strict: false,
copy_grants: false,
enable_schema_evolution: None,
change_tracking: None,
data_retention_time_in_days: None,
max_data_extension_time_in_days: None,
default_ddl_collation: None,
with_aggregation_policy: None,
with_row_access_policy: None,
with_tags: None,
}),
);
}
}
fn ms() -> TestedDialects {
TestedDialects {
dialects: vec![Box::new(MsSqlDialect {})],