Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

[package]
name = "sqlparser-dsql"
description = "SQL parser fork with Aurora DSQL extensions (CREATE INDEX ASYNC, ALTER TABLE ASYNC, ALTER COLUMN SET STORAGE, order-independent CREATE SEQUENCE, INCLUDE on table constraints). Based on sqlparser 0.62.0."
version = "0.62.4"
description = "SQL parser fork with Aurora DSQL extensions (CREATE INDEX ASYNC, ALTER TABLE ASYNC, ALTER COLUMN DROP IDENTITY/EXPRESSION, ALTER COLUMN SET STORAGE, order-independent CREATE SEQUENCE, INCLUDE on table constraints). Based on sqlparser 0.62.0."
version = "0.62.5"
authors = [
"Apache DataFusion <dev@datafusion.apache.org>",
"Amazon Web Services",
Expand Down
24 changes: 24 additions & 0 deletions src/ast/ddl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1278,6 +1278,16 @@ pub enum AlterColumnOperation {
},
/// `DROP DEFAULT`
DropDefault,
/// `DROP IDENTITY [ IF EXISTS ]`
DropIdentity {
/// Whether `IF EXISTS` was specified.
if_exists: bool,
},
/// `DROP EXPRESSION [ IF EXISTS ]`
DropExpression {
/// Whether `IF EXISTS` was specified.
if_exists: bool,
},
/// `SET STORAGE { PLAIN | EXTERNAL | EXTENDED | MAIN | DEFAULT }`
SetStorage {
/// PostgreSQL column storage strategy.
Expand Down Expand Up @@ -1315,6 +1325,20 @@ impl fmt::Display for AlterColumnOperation {
AlterColumnOperation::DropDefault => {
write!(f, "DROP DEFAULT")
}
AlterColumnOperation::DropIdentity { if_exists } => {
write!(f, "DROP IDENTITY")?;
if *if_exists {
write!(f, " IF EXISTS")?;
}
Ok(())
}
AlterColumnOperation::DropExpression { if_exists } => {
write!(f, "DROP EXPRESSION")?;
if *if_exists {
write!(f, " IF EXISTS")?;
}
Ok(())
}
AlterColumnOperation::SetStorage { storage } => {
write!(f, "SET STORAGE {storage}")
}
Expand Down
4 changes: 4 additions & 0 deletions src/ast/spans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,8 @@ impl Spanned for Analyze {
/// - [AlterColumnOperation::SetNotNull]
/// - [AlterColumnOperation::DropNotNull]
/// - [AlterColumnOperation::DropDefault]
/// - [AlterColumnOperation::DropIdentity]
/// - [AlterColumnOperation::DropExpression]
/// - [AlterColumnOperation::SetStorage]
/// - [AlterColumnOperation::AddGenerated]
impl Spanned for AlterColumnOperation {
Expand All @@ -902,6 +904,8 @@ impl Spanned for AlterColumnOperation {
AlterColumnOperation::DropNotNull => Span::empty(),
AlterColumnOperation::SetDefault { value } => value.span(),
AlterColumnOperation::DropDefault => Span::empty(),
AlterColumnOperation::DropIdentity { .. } => Span::empty(),
AlterColumnOperation::DropExpression { .. } => Span::empty(),
AlterColumnOperation::SetStorage { .. } => Span::empty(),
AlterColumnOperation::SetDataType {
data_type: _,
Expand Down
1 change: 1 addition & 0 deletions src/keywords.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ define_keywords!(
EXPLAIN,
EXPLICIT,
EXPORT,
EXPRESSION,
EXTEND,
EXTENDED,
EXTENSION,
Expand Down
12 changes: 10 additions & 2 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10615,6 +10615,14 @@ impl<'a> Parser<'a> {
}
} else if self.parse_keywords(&[Keyword::DROP, Keyword::DEFAULT]) {
AlterColumnOperation::DropDefault {}
} else if self.parse_keywords(&[Keyword::DROP, Keyword::IDENTITY]) {
AlterColumnOperation::DropIdentity {
if_exists: self.parse_keywords(&[Keyword::IF, Keyword::EXISTS]),
}
} else if self.parse_keywords(&[Keyword::DROP, Keyword::EXPRESSION]) {
AlterColumnOperation::DropExpression {
if_exists: self.parse_keywords(&[Keyword::IF, Keyword::EXISTS]),
}
} else if self.parse_keywords(&[Keyword::SET, Keyword::STORAGE]) {
let storage = self.parse_column_storage()?;
AlterColumnOperation::SetStorage { storage }
Expand Down Expand Up @@ -10647,9 +10655,9 @@ impl<'a> Parser<'a> {
}
} else {
let message = if is_postgresql {
"SET/DROP NOT NULL, SET DEFAULT, SET STORAGE, SET DATA TYPE, or ADD GENERATED after ALTER COLUMN"
"SET/DROP NOT NULL, SET/DROP DEFAULT, DROP IDENTITY, DROP EXPRESSION, SET STORAGE, SET DATA TYPE, or ADD GENERATED after ALTER COLUMN"
} else {
"SET/DROP NOT NULL, SET DEFAULT, SET STORAGE, or SET DATA TYPE after ALTER COLUMN"
"SET/DROP NOT NULL, SET/DROP DEFAULT, DROP IDENTITY, DROP EXPRESSION, SET STORAGE, or SET DATA TYPE after ALTER COLUMN"
};

return self.expected_ref(message, self.peek_token_ref());
Expand Down
18 changes: 18 additions & 0 deletions tests/sqlparser_postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1110,6 +1110,24 @@ fn parse_alter_table_alter_column_set_storage() {
}
}

#[test]
fn parse_alter_table_alter_column_drop_identity() {
for suffix in ["", " IF EXISTS"] {
pg_and_generic().verified_stmt(&format!(
"ALTER TABLE tab ALTER COLUMN id DROP IDENTITY{suffix}"
));
}
}

#[test]
fn parse_alter_table_alter_column_drop_expression() {
for suffix in ["", " IF EXISTS"] {
pg_and_generic().verified_stmt(&format!(
"ALTER TABLE tab ALTER COLUMN generated_value DROP EXPRESSION{suffix}"
));
}
}

#[test]
fn parse_create_table_column_storage() {
for (storage, expected) in [
Expand Down
Loading