parse VALIDATE CONSTRAINT

This commit is contained in:
achristmascarl 2025-06-25 14:57:31 -04:00
parent b3da639810
commit 7947c6a72e
5 changed files with 16 additions and 2 deletions

View file

@ -347,6 +347,10 @@ pub enum AlterTableOperation {
equals: bool,
value: ValueWithSpan,
},
/// `VALIDATE CONSTRAINT <name>`
ValidateConstraint {
name: Ident,
},
}
/// An `ALTER Policy` (`Statement::AlterPolicy`) operation
@ -784,6 +788,9 @@ impl fmt::Display for AlterTableOperation {
AlterTableOperation::ReplicaIdentity { identity } => {
write!(f, "REPLICA IDENTITY {identity}")
}
AlterTableOperation::ValidateConstraint { name } => {
write!(f, "VALIDATE CONSTRAINT {name}")
}
}
}
}

View file

@ -1198,6 +1198,7 @@ impl Spanned for AlterTableOperation {
AlterTableOperation::AutoIncrement { value, .. } => value.span(),
AlterTableOperation::Lock { .. } => Span::empty(),
AlterTableOperation::ReplicaIdentity { .. } => Span::empty(),
AlterTableOperation::ValidateConstraint { name } => name.span,
}
}
}

View file

@ -1063,14 +1063,14 @@ pub trait Dialect: Debug + Any {
/// Returns true if the dialect supports `ADD <table_constraint> [NOT VALID]` in `ALTER TABLE` statements.
///
/// -[PostgreSQL](https://www.postgresql.org/docs/17/sql-altertable.html)
/// - [PostgreSQL](https://www.postgresql.org/docs/17/sql-altertable.html)
fn supports_constraint_not_valid(&self) -> bool {
false
}
/// Returns true if the dialect supports `VALIDATE CONSTRAINT <constraint_name>` in `ALTER TABLE` statements.
///
/// -[PostgreSQL](https://www.postgresql.org/docs/17/sql-altertable.html)
/// - [PostgreSQL](https://www.postgresql.org/docs/17/sql-altertable.html)
fn supports_validate_constraint(&self) -> bool {
false
}

View file

@ -981,6 +981,7 @@ define_keywords!(
UUID,
VACUUM,
VALID,
VALIDATE,
VALIDATION_MODE,
VALUE,
VALUES,

View file

@ -8899,6 +8899,11 @@ impl<'a> Parser<'a> {
};
AlterTableOperation::ReplicaIdentity { identity }
} else if self.parse_keywords(&[Keyword::VALIDATE, Keyword::CONSTRAINT])
&& self.dialect.supports_validate_constraint()
{
let name = self.parse_identifier()?;
AlterTableOperation::ValidateConstraint { name }
} else {
let options: Vec<SqlOption> =
self.parse_options_with_keywords(&[Keyword::SET, Keyword::TBLPROPERTIES])?;