Skip to content

Commit 5613dfe

Browse files
author
aleksei.p
committed
update
1 parent 5687466 commit 5613dfe

File tree

4 files changed

+31
-24
lines changed

4 files changed

+31
-24
lines changed

src/ast/ddl.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,20 @@ impl fmt::Display for ColumnOptionDef {
10501050
}
10511051
}
10521052

1053+
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1054+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1055+
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1056+
pub struct IdentityProperty {
1057+
pub seed: Expr,
1058+
pub increment: Expr,
1059+
}
1060+
1061+
impl fmt::Display for IdentityProperty {
1062+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1063+
write!(f, "{}, {}", self.seed, self.increment)
1064+
}
1065+
}
1066+
10531067
/// `ColumnOption`s are modifiers that follow a column definition in a `CREATE
10541068
/// TABLE` statement.
10551069
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
@@ -1126,7 +1140,7 @@ pub enum ColumnOption {
11261140
/// IDENTITY [ (seed , increment) ]
11271141
/// ```
11281142
/// [MS SQL Server]: https://learn.microsoft.com/en-us/sql/t-sql/statements/create-table-transact-sql-identity-property
1129-
Identity(Option<SqlOption>),
1143+
Identity(Option<IdentityProperty>),
11301144
}
11311145

11321146
impl fmt::Display for ColumnOption {

src/ast/mod.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ pub use self::dcl::{AlterRoleOperation, ResetConfig, RoleOption, SetConfigValue,
3636
pub use self::ddl::{
3737
AlterColumnOperation, AlterIndexOperation, AlterTableOperation, ClusteredBy, ColumnDef,
3838
ColumnOption, ColumnOptionDef, ConstraintCharacteristics, Deduplicate, DeferrableInitial,
39-
GeneratedAs, GeneratedExpressionMode, IndexOption, IndexType, KeyOrIndexDisplay, Owner,
40-
Partition, ProcedureParam, ReferentialAction, TableConstraint,
39+
GeneratedAs, GeneratedExpressionMode, IdentityProperty, IndexOption, IndexType,
40+
KeyOrIndexDisplay, Owner, Partition, ProcedureParam, ReferentialAction, TableConstraint,
4141
UserDefinedTypeCompositeAttributeDef, UserDefinedTypeRepresentation, ViewColumnDef,
4242
};
4343
pub use self::dml::{CreateIndex, CreateTable, Delete, Insert};
@@ -5818,13 +5818,6 @@ pub enum SqlOption {
58185818
range_direction: Option<PartitionRangeDirection>,
58195819
for_values: Vec<Expr>,
58205820
},
5821-
/// MS SQL Server specific: Optional parameters of identity column
5822-
/// E.g.
5823-
///
5824-
/// IDENTITY(1, 2)
5825-
///
5826-
/// [MS SQL Server]: https://learn.microsoft.com/en-us/sql/t-sql/statements/create-table-transact-sql-identity-property
5827-
Identity { seed: Value, increment: Value },
58285821
}
58295822

58305823
impl fmt::Display for SqlOption {
@@ -5856,9 +5849,6 @@ impl fmt::Display for SqlOption {
58565849
display_comma_separated(for_values)
58575850
)
58585851
}
5859-
SqlOption::Identity { seed, increment } => {
5860-
write!(f, "{}, {}", seed, increment)
5861-
}
58625852
}
58635853
}
58645854
}

src/parser/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6046,17 +6046,17 @@ impl<'a> Parser<'a> {
60466046
} else if self.parse_keyword(Keyword::IDENTITY)
60476047
&& dialect_of!(self is MsSqlDialect | GenericDialect)
60486048
{
6049-
let parameters = if self.expect_token(&Token::LParen).is_ok() {
6050-
let seed = self.parse_number_value()?;
6049+
let property = if self.consume_token(&Token::LParen) {
6050+
let seed = self.parse_number()?;
60516051
self.expect_token(&Token::Comma)?;
6052-
let increment = self.parse_number_value()?;
6052+
let increment = self.parse_number()?;
60536053
self.expect_token(&Token::RParen)?;
60546054

6055-
Some(SqlOption::Identity { seed, increment })
6055+
Some(IdentityProperty { seed, increment })
60566056
} else {
60576057
None
60586058
};
6059-
Ok(Some(ColumnOption::Identity(parameters)))
6059+
Ok(Some(ColumnOption::Identity(property)))
60606060
} else {
60616061
Ok(None)
60626062
}

tests/sqlparser_mssql.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -930,14 +930,17 @@ fn parse_create_table_with_identity_column() {
930930
ColumnOptionDef {
931931
name: None,
932932
#[cfg(not(feature = "bigdecimal"))]
933-
option: ColumnOption::Identity(Some(SqlOption::Identity {
934-
seed: Value::Number("1".to_string(), false),
935-
increment: Value::Number("1".to_string(), false),
933+
option: ColumnOption::Identity(Some(IdentityProperty {
934+
seed: Expr::Value(Value::Number("1".to_string(), false)),
935+
increment: Expr::Value(Value::Number("1".to_string(), false)),
936936
})),
937937
#[cfg(feature = "bigdecimal")]
938-
option: ColumnOption::Identity(Some(SqlOption::Identity {
939-
seed: Value::Number(bigdecimal::BigDecimal::from(1), false),
940-
increment: Value::Number(bigdecimal::BigDecimal::from(1), false),
938+
option: ColumnOption::Identity(Some(IdentityProperty {
939+
seed: Expr::Value(Value::Number(bigdecimal::BigDecimal::from(1), false)),
940+
increment: Expr::Value(Value::Number(
941+
bigdecimal::BigDecimal::from(1),
942+
false,
943+
)),
941944
})),
942945
},
943946
ColumnOptionDef {

0 commit comments

Comments
 (0)