Skip to content

Commit 91fb5da

Browse files
committed
Alphabetise
1 parent abfc55e commit 91fb5da

File tree

3 files changed

+49
-69
lines changed

3 files changed

+49
-69
lines changed

src/ast/ddl.rs

Lines changed: 25 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +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
48+
/// `DISABLE ROW LEVEL SECURITY`
5149
///
5250
/// Note: this is a PostgreSQL-specific operation.
53-
DisableTrigger {
54-
name: Ident,
55-
},
56-
DisableRule {
57-
name: Ident,
58-
},
5951
DisableRowLevelSecurity,
52+
/// `DISABLE RULE rewrite_rule_name`
53+
///
54+
/// Note: this is a PostgreSQL-specific operation.
55+
DisableRule { name: Ident },
56+
/// `DISABLE TRIGGER [ trigger_name | ALL | USER ]`
57+
///
58+
/// Note: this is a PostgreSQL-specific operation.
59+
DisableTrigger { name: Ident },
6060
/// `DROP CONSTRAINT [ IF EXISTS ] <name>`
6161
DropConstraint {
6262
if_exists: bool,
@@ -73,47 +73,34 @@ pub enum AlterTableOperation {
7373
///
7474
/// Note: this is a MySQL-specific operation.
7575
DropPrimaryKey,
76-
77-
/// `ENABLE TRIGGER [ trigger_name | ALL | USER ]`
76+
/// `ENABLE ALWAYS RULE rewrite_rule_name`
7877
///
7978
/// Note: this is a PostgreSQL-specific operation.
80-
EnableTrigger {
81-
name: Ident,
82-
},
83-
/// `ENABLE RULE rewrite_rule_name`
79+
EnableAlwaysRule { name: Ident },
80+
/// `ENABLE ALWAYS TRIGGER trigger_name`
8481
///
8582
/// Note: this is a PostgreSQL-specific operation.
86-
EnableRule {
87-
name: Ident,
88-
},
89-
/// `ENABLE ROW LEVEL SECURITY`
83+
EnableAlwaysTrigger { name: Ident },
84+
/// `ENABLE REPLICA RULE rewrite_rule_name`
9085
///
9186
/// Note: this is a PostgreSQL-specific operation.
92-
EnableRowLevelSecurity,
87+
EnableReplicaRule { name: Ident },
9388
/// `ENABLE REPLICA TRIGGER trigger_name`
9489
///
9590
/// Note: this is a PostgreSQL-specific operation.
96-
EnableReplicaTrigger {
97-
name: Ident,
98-
},
99-
/// `ENABLE ALWAYS TRIGGER trigger_name`
91+
EnableReplicaTrigger { name: Ident },
92+
/// `ENABLE ROW LEVEL SECURITY`
10093
///
10194
/// Note: this is a PostgreSQL-specific operation.
102-
EnableAlwaysTrigger {
103-
name: Ident,
104-
},
105-
/// `ENABLE REPLICA RULE rewrite_rule_name`
95+
EnableRowLevelSecurity,
96+
/// `ENABLE RULE rewrite_rule_name`
10697
///
10798
/// Note: this is a PostgreSQL-specific operation.
108-
EnableReplicaRule {
109-
name: Ident,
110-
},
111-
/// `ENABLE ALWAYS RULE rewrite_rule_name`
99+
EnableRule { name: Ident },
100+
/// `ENABLE TRIGGER [ trigger_name | ALL | USER ]`
112101
///
113102
/// Note: this is a PostgreSQL-specific operation.
114-
EnableAlwaysRule {
115-
name: Ident,
116-
},
103+
EnableTrigger { name: Ident },
117104
/// `RENAME TO PARTITION (partition=val)`
118105
RenamePartitions {
119106
old_partitions: Vec<Expr>,
@@ -134,9 +121,7 @@ pub enum AlterTableOperation {
134121
new_column_name: Ident,
135122
},
136123
/// `RENAME TO <table_name>`
137-
RenameTable {
138-
table_name: ObjectName,
139-
},
124+
RenameTable { table_name: ObjectName },
140125
// CHANGE [ COLUMN ] <old_name> <new_name> <data_type> [ <options> ]
141126
ChangeColumn {
142127
old_name: Ident,
@@ -147,10 +132,7 @@ pub enum AlterTableOperation {
147132
/// `RENAME CONSTRAINT <old_constraint_name> TO <new_constraint_name>`
148133
///
149134
/// Note: this is a PostgreSQL-specific operation.
150-
RenameConstraint {
151-
old_name: Ident,
152-
new_name: Ident,
153-
},
135+
RenameConstraint { old_name: Ident, new_name: Ident },
154136
/// `ALTER [ COLUMN ]`
155137
AlterColumn {
156138
column_name: Ident,
@@ -159,9 +141,7 @@ pub enum AlterTableOperation {
159141
/// 'SWAP WITH <table_name>'
160142
///
161143
/// Note: this is Snowflake specific <https://docs.snowflake.com/en/sql-reference/sql/alter-table>
162-
SwapWith {
163-
table_name: ObjectName,
164-
},
144+
SwapWith { table_name: ObjectName },
165145
}
166146

167147
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]

src/parser/mod.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4637,44 +4637,44 @@ impl<'a> Parser<'a> {
46374637
}
46384638
}
46394639
} else if self.parse_keyword(Keyword::DISABLE) {
4640-
if self.parse_keyword(Keyword::TRIGGER) {
4641-
let name = self.parse_identifier()?;
4642-
AlterTableOperation::DisableTrigger { name }
4640+
if self.parse_keywords(&[Keyword::ROW, Keyword::LEVEL, Keyword::SECURITY]) {
4641+
AlterTableOperation::DisableRowLevelSecurity {}
46434642
} else if self.parse_keyword(Keyword::RULE) {
46444643
let name = self.parse_identifier()?;
46454644
AlterTableOperation::DisableRule { name }
4646-
} else if self.parse_keywords(&[Keyword::ROW, Keyword::LEVEL, Keyword::SECURITY]) {
4647-
AlterTableOperation::DisableRowLevelSecurity {}
4645+
} else if self.parse_keyword(Keyword::TRIGGER) {
4646+
let name = self.parse_identifier()?;
4647+
AlterTableOperation::DisableTrigger { name }
46484648
} else {
46494649
return self.expected(
4650-
"TRIGGER, RULE or ROW LEVEL SECURITY after DISABLE",
4650+
"ROW LEVEL SECURITY, RULE, or TRIGGER after DISABLE",
46514651
self.peek_token(),
46524652
);
46534653
}
46544654
} else if self.parse_keyword(Keyword::ENABLE) {
4655-
if self.parse_keyword(Keyword::TRIGGER) {
4655+
if self.parse_keywords(&[Keyword::ALWAYS, Keyword::RULE]) {
46564656
let name = self.parse_identifier()?;
4657-
AlterTableOperation::EnableTrigger { name }
4658-
} else if self.parse_keyword(Keyword::RULE) {
4657+
AlterTableOperation::EnableAlwaysRule { name }
4658+
} else if self.parse_keywords(&[Keyword::ALWAYS, Keyword::TRIGGER]) {
46594659
let name = self.parse_identifier()?;
4660-
AlterTableOperation::EnableRule { name }
4660+
AlterTableOperation::EnableAlwaysTrigger { name }
46614661
} else if self.parse_keywords(&[Keyword::ROW, Keyword::LEVEL, Keyword::SECURITY]) {
46624662
AlterTableOperation::EnableRowLevelSecurity {}
46634663
} else if self.parse_keywords(&[Keyword::REPLICA, Keyword::RULE]) {
46644664
let name = self.parse_identifier()?;
46654665
AlterTableOperation::EnableReplicaRule { name }
4666-
} else if self.parse_keywords(&[Keyword::ALWAYS, Keyword::RULE]) {
4667-
let name = self.parse_identifier()?;
4668-
AlterTableOperation::EnableAlwaysRule { name }
46694666
} else if self.parse_keywords(&[Keyword::REPLICA, Keyword::TRIGGER]) {
46704667
let name = self.parse_identifier()?;
46714668
AlterTableOperation::EnableReplicaTrigger { name }
4672-
} else if self.parse_keywords(&[Keyword::ALWAYS, Keyword::TRIGGER]) {
4669+
} else if self.parse_keyword(Keyword::RULE) {
46734670
let name = self.parse_identifier()?;
4674-
AlterTableOperation::EnableAlwaysTrigger { name }
4671+
AlterTableOperation::EnableRule { name }
4672+
} else if self.parse_keyword(Keyword::TRIGGER) {
4673+
let name = self.parse_identifier()?;
4674+
AlterTableOperation::EnableTrigger { name }
46754675
} else {
46764676
return self.expected(
4677-
"TRIGGER, RULE or ROW LEVEL SECURITY after ENABLE",
4677+
"ALWAYS, REPLICA, ROW LEVEL SECURITY, RULE, or TRIGGER after ENABLE",
46784678
self.peek_token(),
46794679
);
46804680
}

tests/sqlparser_postgres.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -565,24 +565,24 @@ fn parse_alter_table_constraints_rename() {
565565

566566
#[test]
567567
fn parse_alter_table_disable() {
568+
pg_and_generic().verified_stmt("ALTER TABLE tab DISABLE ROW LEVEL SECURITY");
569+
pg_and_generic().verified_stmt("ALTER TABLE tab DISABLE RULE rule_name");
568570
pg_and_generic().verified_stmt("ALTER TABLE tab DISABLE TRIGGER ALL");
569571
pg_and_generic().verified_stmt("ALTER TABLE tab DISABLE TRIGGER USER");
570572
pg_and_generic().verified_stmt("ALTER TABLE tab DISABLE TRIGGER trigger_name");
571-
pg_and_generic().verified_stmt("ALTER TABLE tab DISABLE RULE rule_name");
572-
pg_and_generic().verified_stmt("ALTER TABLE tab DISABLE ROW LEVEL SECURITY");
573573
}
574574

575575
#[test]
576576
fn parse_alter_table_enable() {
577+
pg_and_generic().verified_stmt("ALTER TABLE tab ENABLE ALWAYS RULE rule_name");
578+
pg_and_generic().verified_stmt("ALTER TABLE tab ENABLE ALWAYS TRIGGER trigger_name");
579+
pg_and_generic().verified_stmt("ALTER TABLE tab ENABLE REPLICA TRIGGER trigger_name");
580+
pg_and_generic().verified_stmt("ALTER TABLE tab ENABLE REPLICA RULE rule_name");
581+
pg_and_generic().verified_stmt("ALTER TABLE tab ENABLE ROW LEVEL SECURITY");
582+
pg_and_generic().verified_stmt("ALTER TABLE tab ENABLE RULE rule_name");
577583
pg_and_generic().verified_stmt("ALTER TABLE tab ENABLE TRIGGER ALL");
578584
pg_and_generic().verified_stmt("ALTER TABLE tab ENABLE TRIGGER USER");
579585
pg_and_generic().verified_stmt("ALTER TABLE tab ENABLE TRIGGER trigger_name");
580-
pg_and_generic().verified_stmt("ALTER TABLE tab ENABLE RULE rule_name");
581-
pg_and_generic().verified_stmt("ALTER TABLE tab ENABLE ROW LEVEL SECURITY");
582-
pg_and_generic().verified_stmt("ALTER TABLE tab ENABLE REPLICA TRIGGER trigger_name");
583-
pg_and_generic().verified_stmt("ALTER TABLE tab ENABLE ALWAYS TRIGGER trigger_name");
584-
pg_and_generic().verified_stmt("ALTER TABLE tab ENABLE REPLICA RULE rule_name");
585-
pg_and_generic().verified_stmt("ALTER TABLE tab ENABLE ALWAYS rule_name");
586586
}
587587
#[test]
588588
fn parse_alter_table_alter_column() {

0 commit comments

Comments
 (0)