Skip to content

Commit b9b6c42

Browse files
only use in postgres
1 parent 569653b commit b9b6c42

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
@@ -1036,7 +1036,7 @@ pub trait Dialect: Debug + Any {
10361036
/// Returns true if the dialect supports `ADD <table_constraint> [NOT VALID]` in `ALTER TABLE` statements.
10371037
///
10381038
/// -[PostgreSQL](https://www.postgresql.org/docs/17/sql-altertable.html)
1039-
fn supports_constraint_not_validation(&self) -> bool {
1039+
fn supports_constraint_not_valid(&self) -> bool {
10401040
false
10411041
}
10421042

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
@@ -6236,7 +6236,7 @@ fn parse_ts_datatypes() {
62366236

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

0 commit comments

Comments
 (0)