Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
7phs committed Sep 30, 2024
1 parent d285272 commit 3cfb810
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/ast/ddl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1100,10 +1100,10 @@ pub enum IdentityOrder {
impl fmt::Display for IdentityProperty {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if let Some(parameters) = &self.parameters {
write!(f, "{parameters}")?;
write!(f, " {parameters}")?;
}
if let Some(order) = &self.order {
write!(f, "{order}")?;
write!(f, " {order}")?;
}
Ok(())
}
Expand All @@ -1116,7 +1116,7 @@ impl fmt::Display for IdentityParameters {
write!(f, "({}, {})", self.seed, self.increment)
}
IdentityParametersFormat::StartIncrement => {
write!(f, "START {} INCREMENT {})", self.seed, self.increment)
write!(f, "START {} INCREMENT {}", self.seed, self.increment)
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ pub use self::dcl::{AlterRoleOperation, ResetConfig, RoleOption, SetConfigValue,
pub use self::ddl::{
AlterColumnOperation, AlterIndexOperation, AlterTableOperation, ClusteredBy, ColumnDef,
ColumnOption, ColumnOptionDef, ConstraintCharacteristics, Deduplicate, DeferrableInitial,
GeneratedAs, GeneratedExpressionMode, IdentityParameters, IdentityParametersFormat,
IdentityProperty, IdentityPropertyCommand, IndexOption, IndexType, KeyOrIndexDisplay, Owner,
Partition, ProcedureParam, ReferentialAction, TableConstraint,
GeneratedAs, GeneratedExpressionMode, IdentityOrder, IdentityParameters,
IdentityParametersFormat, IdentityProperty, IdentityPropertyCommand, IndexOption, IndexType,
KeyOrIndexDisplay, Owner, Partition, ProcedureParam, ReferentialAction, TableConstraint,
UserDefinedTypeCompositeAttributeDef, UserDefinedTypeRepresentation, ViewColumnDef,
};
pub use self::dml::{CreateIndex, CreateTable, Delete, Insert};
Expand Down
1 change: 1 addition & 0 deletions src/keywords.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ define_keywords!(
NOINHERIT,
NOLOGIN,
NONE,
NOORDER,
NOREPLICATION,
NORMALIZE,
NOSCAN,
Expand Down
46 changes: 46 additions & 0 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6146,6 +6146,52 @@ impl<'a> Parser<'a> {
Ok(Some(ColumnOption::DialectSpecific(vec![
Token::make_keyword("AUTO_INCREMENT"),
])))
} else if self
.parse_one_of_keywords(&[Keyword::IDENTITY, Keyword::AUTOINCREMENT])
.is_some()
&& dialect_of!(self is SnowflakeDialect)
{
self.prev_token();
let format =
match self.parse_one_of_keywords(&[Keyword::IDENTITY, Keyword::AUTOINCREMENT]) {
Some(Keyword::IDENTITY) => IdentityPropertyCommand::Identity,
Some(Keyword::AUTOINCREMENT) => IdentityPropertyCommand::Autoincrement,
_ => self.expected("one of IDENTITY or AUTOINCREMENT", self.peek_token())?,
};
let parameters = if self.consume_token(&Token::LParen) {
let seed = self.parse_number()?;
self.expect_token(&Token::Comma)?;
let increment = self.parse_number()?;
self.expect_token(&Token::RParen)?;

Some(IdentityParameters {
format: IdentityParametersFormat::FunctionCall,
seed,
increment,
})
} else if self.parse_keyword(Keyword::START) {
let seed = self.parse_number()?;
self.expect_keyword(Keyword::INCREMENT)?;
let increment = self.parse_number()?;

Some(IdentityParameters {
format: IdentityParametersFormat::StartIncrement,
seed,
increment,
})
} else {
None
};
let order = match self.parse_one_of_keywords(&[Keyword::ORDER, Keyword::NOORDER]) {
Some(Keyword::ORDER) => Some(IdentityOrder::Order),
Some(Keyword::NOORDER) => Some(IdentityOrder::Noorder),
_ => None,
};
Ok(Some(ColumnOption::Identity(IdentityProperty {
format,
parameters,
order,
})))
} else if self.parse_keyword(Keyword::AUTOINCREMENT)
&& dialect_of!(self is SQLiteDialect | GenericDialect)
{
Expand Down
13 changes: 13 additions & 0 deletions tests/sqlparser_snowflake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,19 @@ fn test_snowflake_single_line_tokenize() {
assert_eq!(expected, tokens);
}

#[test]
fn test_snowflake_create_table_with_all_parameters() {
let sql = concat!(
"CREATE TABLE my_table (",
"a INT AUTOINCREMENT ORDER, ",
"b INT AUTOINCREMENT (100, -1) NOORDER, ",
"c INT IDENTITY, ",
"d INT IDENTITY START 100 INCREMENT -1 ORDER",
")"
);
snowflake().verified_stmt(sql);
}

#[test]
fn parse_sf_create_or_replace_view_with_comment_missing_equal() {
assert!(snowflake_and_generic()
Expand Down

0 comments on commit 3cfb810

Please sign in to comment.