From 7947c6a72e461226e7bd25e269f426c44555b2f0 Mon Sep 17 00:00:00 2001 From: achristmascarl Date: Wed, 25 Jun 2025 14:57:31 -0400 Subject: [PATCH] parse VALIDATE CONSTRAINT --- src/ast/ddl.rs | 7 +++++++ src/ast/spans.rs | 1 + src/dialect/mod.rs | 4 ++-- src/keywords.rs | 1 + src/parser/mod.rs | 5 +++++ 5 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/ast/ddl.rs b/src/ast/ddl.rs index 108349c8..63c5af37 100644 --- a/src/ast/ddl.rs +++ b/src/ast/ddl.rs @@ -347,6 +347,10 @@ pub enum AlterTableOperation { equals: bool, value: ValueWithSpan, }, + /// `VALIDATE CONSTRAINT ` + 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}") + } } } } diff --git a/src/ast/spans.rs b/src/ast/spans.rs index 43d7b77f..e9c1d9ef 100644 --- a/src/ast/spans.rs +++ b/src/ast/spans.rs @@ -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, } } } diff --git a/src/dialect/mod.rs b/src/dialect/mod.rs index 97bd4a72..2ceea10e 100644 --- a/src/dialect/mod.rs +++ b/src/dialect/mod.rs @@ -1063,14 +1063,14 @@ pub trait Dialect: Debug + Any { /// Returns true if the dialect supports `ADD [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 ` 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 } diff --git a/src/keywords.rs b/src/keywords.rs index a8bbca3d..49a54e8a 100644 --- a/src/keywords.rs +++ b/src/keywords.rs @@ -981,6 +981,7 @@ define_keywords!( UUID, VACUUM, VALID, + VALIDATE, VALIDATION_MODE, VALUE, VALUES, diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 9e4b3a64..c45f0c35 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -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 = self.parse_options_with_keywords(&[Keyword::SET, Keyword::TBLPROPERTIES])?;