Skip to content

Commit 9298cc4

Browse files
committed
Add support for DISABLE on ALTER TABLE for pg
1 parent c62ecb1 commit 9298cc4

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed

src/ast/ddl.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@ pub enum AlterTableOperation {
4545
/// <column_def>.
4646
column_def: ColumnDef,
4747
},
48+
/// DISABLE TRIGGER [ trigger_name | ALL | USER ]
49+
/// DISABLE RULE rewrite_rule_name
50+
/// DISABLE ROW LEVEL SECURITY
51+
///
52+
/// Note: this is a PostgreSQL-specific operation.
53+
DisableTrigger {
54+
name: Ident,
55+
},
56+
DisableRule {
57+
name: Ident,
58+
},
59+
DisableRowLevelSecurity,
4860
/// `DROP CONSTRAINT [ IF EXISTS ] <name>`
4961
DropConstraint {
5062
if_exists: bool,
@@ -143,6 +155,15 @@ impl fmt::Display for AlterTableOperation {
143155
AlterTableOperation::AlterColumn { column_name, op } => {
144156
write!(f, "ALTER COLUMN {column_name} {op}")
145157
}
158+
AlterTableOperation::DisableTrigger { name } => {
159+
write!(f, "DISABLE TRIGGER {name}")
160+
}
161+
AlterTableOperation::DisableRule { name } => {
162+
write!(f, "DISABLE RULE {name}")
163+
}
164+
AlterTableOperation::DisableRowLevelSecurity => {
165+
write!(f, "DISABLE ROW LEVEL SECURITY")
166+
}
146167
AlterTableOperation::DropPartitions {
147168
partitions,
148169
if_exists,

src/keywords.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ define_keywords!(
222222
DETAIL,
223223
DETERMINISTIC,
224224
DIRECTORY,
225+
DISABLE,
225226
DISCARD,
226227
DISCONNECT,
227228
DISTINCT,
@@ -557,6 +558,7 @@ define_keywords!(
557558
ROWID,
558559
ROWS,
559560
ROW_NUMBER,
561+
RULE,
560562
RUN,
561563
SAFE_CAST,
562564
SAVEPOINT,

src/parser/mod.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4636,6 +4636,26 @@ impl<'a> Parser<'a> {
46364636
new_column_name,
46374637
}
46384638
}
4639+
} else if self.parse_keyword(Keyword::DISABLE) {
4640+
if self.parse_keyword(Keyword::TRIGGER) {
4641+
// let all = self.parse_keyword(Keyword::ALL);
4642+
// let user = self.parse_keyword(Keyword::ALL);
4643+
let name = self.parse_identifier()?;
4644+
4645+
// println!("parse all: {}", all);
4646+
4647+
AlterTableOperation::DisableTrigger { name }
4648+
} else if self.parse_keyword(Keyword::RULE) {
4649+
let name = self.parse_identifier()?;
4650+
AlterTableOperation::DisableRule { name }
4651+
} else if self.parse_keyword(Keyword::ROW) {
4652+
AlterTableOperation::DisableRowLevelSecurity {}
4653+
} else {
4654+
return self.expected(
4655+
"TRIGGER, RULE or ROW LEVEL SECURITY after DISABLE",
4656+
self.peek_token(),
4657+
);
4658+
}
46394659
} else if self.parse_keyword(Keyword::DROP) {
46404660
if self.parse_keywords(&[Keyword::IF, Keyword::EXISTS, Keyword::PARTITION]) {
46414661
self.expect_token(&Token::LParen)?;

tests/sqlparser_postgres.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,13 @@ fn parse_alter_table_constraints_rename() {
563563
}
564564
}
565565

566+
#[test]
567+
fn parse_alter_table_disable_trigger() {
568+
pg_and_generic().verified_stmt("ALTER TABLE tab DISABLE TRIGGER ALL");
569+
pg_and_generic().verified_stmt("ALTER TABLE tab DISABLE TRIGGER USER");
570+
pg_and_generic().verified_stmt("ALTER TABLE tab DISABLE TRIGGER trigger_name");
571+
}
572+
566573
#[test]
567574
fn parse_alter_table_alter_column() {
568575
pg().one_statement_parses_to(

0 commit comments

Comments
 (0)