Skip to content
Open
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, order-independent CREATE SEQUENCE, INCLUDE on table constraints). Based on sqlparser 0.62.0."
version = "0.62.1"
description = "SQL parser fork with Aurora DSQL extensions (CREATE INDEX ASYNC, ALTER TABLE ASYNC, order-independent CREATE SEQUENCE, INCLUDE on table constraints). Based on sqlparser 0.62.0."
version = "0.62.2"
authors = [
"Apache DataFusion <dev@datafusion.apache.org>",
"Amazon Web Services",
Expand Down
9 changes: 9 additions & 0 deletions src/ast/ddl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4730,6 +4730,12 @@ pub struct AlterTable {
/// Table name
#[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
pub name: ObjectName,
/// Whether the `ASYNC` keyword was specified ([DSQL]). `ALTER TABLE ASYNC`
/// runs the operation as an asynchronous DDL job, e.g.
/// `ALTER TABLE ASYNC t VALIDATE CONSTRAINT c`.
///
/// [DSQL]: https://docs.aws.amazon.com/aurora-dsql/latest/userguide/working-with-postgresql-compatibility.html
pub r#async: bool,
/// Whether `IF EXISTS` was specified for the `ALTER TABLE`.
pub if_exists: bool,
/// Whether the `ONLY` keyword was used (restrict scope to the named table).
Expand Down Expand Up @@ -4757,6 +4763,9 @@ impl fmt::Display for AlterTable {
None => write!(f, "ALTER TABLE ")?,
}

if self.r#async {
write!(f, "ASYNC ")?;
}
if self.if_exists {
write!(f, "IF EXISTS ")?;
}
Expand Down
2 changes: 2 additions & 0 deletions src/dialect/snowflake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,7 @@ fn parse_alter_dynamic_table(parser: &mut Parser) -> Result<Statement, ParserErr

Ok(Statement::AlterTable(AlterTable {
name: table_name,
r#async: false,
if_exists: false,
only: false,
operations: vec![operation],
Expand Down Expand Up @@ -786,6 +787,7 @@ fn parse_alter_external_table(parser: &mut Parser) -> Result<Statement, ParserEr

Ok(Statement::AlterTable(AlterTable {
name: table_name,
r#async: false,
if_exists,
only: false,
operations: vec![operation],
Expand Down
2 changes: 2 additions & 0 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11111,6 +11111,7 @@ impl<'a> Parser<'a> {

/// Parse a [Statement::AlterTable]
pub fn parse_alter_table(&mut self, iceberg: bool) -> Result<Statement, ParserError> {
let r#async = self.parse_keyword(Keyword::ASYNC); // [ ASYNC ] (DSQL)
let if_exists = self.parse_keywords(&[Keyword::IF, Keyword::EXISTS]);
let only = self.parse_keyword(Keyword::ONLY); // [ ONLY ]
let table_name = self.parse_object_name(false)?;
Expand Down Expand Up @@ -11138,6 +11139,7 @@ impl<'a> Parser<'a> {

Ok(AlterTable {
name: table_name,
r#async,
if_exists,
only,
operations,
Expand Down
33 changes: 32 additions & 1 deletion tests/sqlparser_postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7214,7 +7214,12 @@ fn parse_alter_table_constraint_not_valid() {
#[test]
fn parse_alter_table_validate_constraint() {
match pg_and_generic().verified_stmt("ALTER TABLE foo VALIDATE CONSTRAINT bar") {
Statement::AlterTable(AlterTable { operations, .. }) => {
Statement::AlterTable(AlterTable {
operations,
r#async,
..
}) => {
assert!(!r#async);
assert_eq!(
operations,
vec![AlterTableOperation::ValidateConstraint { name: "bar".into() }]
Expand All @@ -7224,6 +7229,32 @@ fn parse_alter_table_validate_constraint() {
}
}

#[test]
fn parse_alter_table_async_validate_constraint() {
// Aurora DSQL runs VALIDATE CONSTRAINT as an asynchronous DDL job via the
// `ALTER TABLE ASYNC` form.
match pg_and_generic().verified_stmt("ALTER TABLE ASYNC foo VALIDATE CONSTRAINT bar") {
Statement::AlterTable(AlterTable {
name,
operations,
r#async,
..
}) => {
assert!(r#async);
assert_eq!(name.to_string(), "foo");
assert_eq!(
operations,
vec![AlterTableOperation::ValidateConstraint { name: "bar".into() }]
);
}
_ => unreachable!(),
}

// ASYNC composes with IF EXISTS and ONLY.
pg_and_generic()
.verified_stmt("ALTER TABLE ASYNC IF EXISTS ONLY foo VALIDATE CONSTRAINT bar");
}

#[test]
fn parse_create_server() {
let test_cases = vec![
Expand Down