Postgres: support ADD CONSTRAINT NOT VALID and VALIDATE CONSTRAINT (#1908)

This commit is contained in:
carl 2025-07-03 12:19:26 -04:00 committed by GitHub
parent 015caca611
commit 418b94227a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 99 additions and 22 deletions

View file

@ -8477,7 +8477,11 @@ impl<'a> Parser<'a> {
pub fn parse_alter_table_operation(&mut self) -> Result<AlterTableOperation, ParserError> {
let operation = if self.parse_keyword(Keyword::ADD) {
if let Some(constraint) = self.parse_optional_table_constraint()? {
AlterTableOperation::AddConstraint(constraint)
let not_valid = self.parse_keywords(&[Keyword::NOT, Keyword::VALID]);
AlterTableOperation::AddConstraint {
constraint,
not_valid,
}
} else if dialect_of!(self is ClickHouseDialect|GenericDialect)
&& self.parse_keyword(Keyword::PROJECTION)
{
@ -8886,6 +8890,9 @@ impl<'a> Parser<'a> {
};
AlterTableOperation::ReplicaIdentity { identity }
} else if self.parse_keywords(&[Keyword::VALIDATE, Keyword::CONSTRAINT]) {
let name = self.parse_identifier()?;
AlterTableOperation::ValidateConstraint { name }
} else {
let options: Vec<SqlOption> =
self.parse_options_with_keywords(&[Keyword::SET, Keyword::TBLPROPERTIES])?;