Skip to content

Commit 7947c6a

Browse files
parse VALIDATE CONSTRAINT
1 parent b3da639 commit 7947c6a

File tree

5 files changed

+16
-2
lines changed

5 files changed

+16
-2
lines changed

src/ast/ddl.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,10 @@ pub enum AlterTableOperation {
347347
equals: bool,
348348
value: ValueWithSpan,
349349
},
350+
/// `VALIDATE CONSTRAINT <name>`
351+
ValidateConstraint {
352+
name: Ident,
353+
},
350354
}
351355

352356
/// An `ALTER Policy` (`Statement::AlterPolicy`) operation
@@ -784,6 +788,9 @@ impl fmt::Display for AlterTableOperation {
784788
AlterTableOperation::ReplicaIdentity { identity } => {
785789
write!(f, "REPLICA IDENTITY {identity}")
786790
}
791+
AlterTableOperation::ValidateConstraint { name } => {
792+
write!(f, "VALIDATE CONSTRAINT {name}")
793+
}
787794
}
788795
}
789796
}

src/ast/spans.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,6 +1198,7 @@ impl Spanned for AlterTableOperation {
11981198
AlterTableOperation::AutoIncrement { value, .. } => value.span(),
11991199
AlterTableOperation::Lock { .. } => Span::empty(),
12001200
AlterTableOperation::ReplicaIdentity { .. } => Span::empty(),
1201+
AlterTableOperation::ValidateConstraint { name } => name.span,
12011202
}
12021203
}
12031204
}

src/dialect/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,14 +1063,14 @@ pub trait Dialect: Debug + Any {
10631063

10641064
/// Returns true if the dialect supports `ADD <table_constraint> [NOT VALID]` in `ALTER TABLE` statements.
10651065
///
1066-
/// -[PostgreSQL](https://www.postgresql.org/docs/17/sql-altertable.html)
1066+
/// - [PostgreSQL](https://www.postgresql.org/docs/17/sql-altertable.html)
10671067
fn supports_constraint_not_valid(&self) -> bool {
10681068
false
10691069
}
10701070

10711071
/// Returns true if the dialect supports `VALIDATE CONSTRAINT <constraint_name>` in `ALTER TABLE` statements.
10721072
///
1073-
/// -[PostgreSQL](https://www.postgresql.org/docs/17/sql-altertable.html)
1073+
/// - [PostgreSQL](https://www.postgresql.org/docs/17/sql-altertable.html)
10741074
fn supports_validate_constraint(&self) -> bool {
10751075
false
10761076
}

src/keywords.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -981,6 +981,7 @@ define_keywords!(
981981
UUID,
982982
VACUUM,
983983
VALID,
984+
VALIDATE,
984985
VALIDATION_MODE,
985986
VALUE,
986987
VALUES,

src/parser/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8899,6 +8899,11 @@ impl<'a> Parser<'a> {
88998899
};
89008900

89018901
AlterTableOperation::ReplicaIdentity { identity }
8902+
} else if self.parse_keywords(&[Keyword::VALIDATE, Keyword::CONSTRAINT])
8903+
&& self.dialect.supports_validate_constraint()
8904+
{
8905+
let name = self.parse_identifier()?;
8906+
AlterTableOperation::ValidateConstraint { name }
89028907
} else {
89038908
let options: Vec<SqlOption> =
89048909
self.parse_options_with_keywords(&[Keyword::SET, Keyword::TBLPROPERTIES])?;

0 commit comments

Comments
 (0)