Skip to content

Commit b3da639

Browse files
only use in postgres
1 parent 0e174c2 commit b3da639

File tree

4 files changed

+7
-4
lines changed

4 files changed

+7
-4
lines changed

src/dialect/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1064,7 +1064,7 @@ pub trait Dialect: Debug + Any {
10641064
/// Returns true if the dialect supports `ADD <table_constraint> [NOT VALID]` in `ALTER TABLE` statements.
10651065
///
10661066
/// -[PostgreSQL](https://www.postgresql.org/docs/17/sql-altertable.html)
1067-
fn supports_constraint_not_validation(&self) -> bool {
1067+
fn supports_constraint_not_valid(&self) -> bool {
10681068
false
10691069
}
10701070

src/dialect/postgresql.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ impl Dialect for PostgreSqlDialect {
259259
true
260260
}
261261

262-
fn supports_constraint_not_validation(&self) -> bool {
262+
fn supports_constraint_not_valid(&self) -> bool {
263263
true
264264
}
265265

src/parser/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8477,7 +8477,10 @@ impl<'a> Parser<'a> {
84778477
pub fn parse_alter_table_operation(&mut self) -> Result<AlterTableOperation, ParserError> {
84788478
let operation = if self.parse_keyword(Keyword::ADD) {
84798479
if let Some(constraint) = self.parse_optional_table_constraint()? {
8480-
let not_valid = self.parse_keywords(&[Keyword::NOT, Keyword::VALID]);
8480+
let mut not_valid = false;
8481+
if self.dialect.supports_constraint_not_valid() {
8482+
not_valid = self.parse_keywords(&[Keyword::NOT, Keyword::VALID]);
8483+
}
84818484
AlterTableOperation::AddConstraint {
84828485
constraint,
84838486
not_valid,

tests/sqlparser_postgres.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6235,7 +6235,7 @@ fn parse_ts_datatypes() {
62356235

62366236
#[test]
62376237
fn parse_alter_table_constraint_not_valid() {
6238-
match pg_and_generic().verified_stmt(
6238+
match pg().verified_stmt(
62396239
"ALTER TABLE foo ADD CONSTRAINT bar FOREIGN KEY (baz) REFERENCES other(ref) NOT VALID",
62406240
) {
62416241
Statement::AlterTable { operations, .. } => {

0 commit comments

Comments
 (0)