From 9298cc4c106ab9e869e817127371f96f9605cad7 Mon Sep 17 00:00:00 2001 From: Toby Hede Date: Fri, 29 Dec 2023 16:16:00 +1100 Subject: [PATCH 1/4] Add support for DISABLE on ALTER TABLE for pg --- src/ast/ddl.rs | 21 +++++++++++++++++++++ src/keywords.rs | 2 ++ src/parser/mod.rs | 20 ++++++++++++++++++++ tests/sqlparser_postgres.rs | 7 +++++++ 4 files changed, 50 insertions(+) diff --git a/src/ast/ddl.rs b/src/ast/ddl.rs index 961bbef79..6cb479e02 100644 --- a/src/ast/ddl.rs +++ b/src/ast/ddl.rs @@ -45,6 +45,18 @@ pub enum AlterTableOperation { /// . column_def: ColumnDef, }, + /// DISABLE TRIGGER [ trigger_name | ALL | USER ] + /// DISABLE RULE rewrite_rule_name + /// DISABLE ROW LEVEL SECURITY + /// + /// Note: this is a PostgreSQL-specific operation. + DisableTrigger { + name: Ident, + }, + DisableRule { + name: Ident, + }, + DisableRowLevelSecurity, /// `DROP CONSTRAINT [ IF EXISTS ] ` DropConstraint { if_exists: bool, @@ -143,6 +155,15 @@ impl fmt::Display for AlterTableOperation { AlterTableOperation::AlterColumn { column_name, op } => { write!(f, "ALTER COLUMN {column_name} {op}") } + AlterTableOperation::DisableTrigger { name } => { + write!(f, "DISABLE TRIGGER {name}") + } + AlterTableOperation::DisableRule { name } => { + write!(f, "DISABLE RULE {name}") + } + AlterTableOperation::DisableRowLevelSecurity => { + write!(f, "DISABLE ROW LEVEL SECURITY") + } AlterTableOperation::DropPartitions { partitions, if_exists, diff --git a/src/keywords.rs b/src/keywords.rs index a6a29159e..24750ef56 100644 --- a/src/keywords.rs +++ b/src/keywords.rs @@ -222,6 +222,7 @@ define_keywords!( DETAIL, DETERMINISTIC, DIRECTORY, + DISABLE, DISCARD, DISCONNECT, DISTINCT, @@ -557,6 +558,7 @@ define_keywords!( ROWID, ROWS, ROW_NUMBER, + RULE, RUN, SAFE_CAST, SAVEPOINT, diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 853ab3d17..c0d308e79 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -4636,6 +4636,26 @@ impl<'a> Parser<'a> { new_column_name, } } + } else if self.parse_keyword(Keyword::DISABLE) { + if self.parse_keyword(Keyword::TRIGGER) { + // let all = self.parse_keyword(Keyword::ALL); + // let user = self.parse_keyword(Keyword::ALL); + let name = self.parse_identifier()?; + + // println!("parse all: {}", all); + + AlterTableOperation::DisableTrigger { name } + } else if self.parse_keyword(Keyword::RULE) { + let name = self.parse_identifier()?; + AlterTableOperation::DisableRule { name } + } else if self.parse_keyword(Keyword::ROW) { + AlterTableOperation::DisableRowLevelSecurity {} + } else { + return self.expected( + "TRIGGER, RULE or ROW LEVEL SECURITY after DISABLE", + self.peek_token(), + ); + } } else if self.parse_keyword(Keyword::DROP) { if self.parse_keywords(&[Keyword::IF, Keyword::EXISTS, Keyword::PARTITION]) { self.expect_token(&Token::LParen)?; diff --git a/tests/sqlparser_postgres.rs b/tests/sqlparser_postgres.rs index b075a9b4d..56f791a38 100644 --- a/tests/sqlparser_postgres.rs +++ b/tests/sqlparser_postgres.rs @@ -563,6 +563,13 @@ fn parse_alter_table_constraints_rename() { } } +#[test] +fn parse_alter_table_disable_trigger() { + pg_and_generic().verified_stmt("ALTER TABLE tab DISABLE TRIGGER ALL"); + pg_and_generic().verified_stmt("ALTER TABLE tab DISABLE TRIGGER USER"); + pg_and_generic().verified_stmt("ALTER TABLE tab DISABLE TRIGGER trigger_name"); +} + #[test] fn parse_alter_table_alter_column() { pg().one_statement_parses_to( From abfc55ee0790667c8a44d058b3c522ca83d5a75a Mon Sep 17 00:00:00 2001 From: Toby Hede Date: Fri, 29 Dec 2023 20:20:19 +1100 Subject: [PATCH 2/4] Add support for ENABLE on ALTER TABLE for pg Signed-off-by: Toby Hede --- src/ast/ddl.rs | 75 +++++++++++++++++++++++++++++++++++-- src/keywords.rs | 3 ++ src/parser/mod.rs | 34 ++++++++++++++--- tests/sqlparser_postgres.rs | 16 +++++++- 4 files changed, 118 insertions(+), 10 deletions(-) diff --git a/src/ast/ddl.rs b/src/ast/ddl.rs index 6cb479e02..c57bce6aa 100644 --- a/src/ast/ddl.rs +++ b/src/ast/ddl.rs @@ -73,6 +73,47 @@ pub enum AlterTableOperation { /// /// Note: this is a MySQL-specific operation. DropPrimaryKey, + + /// `ENABLE TRIGGER [ trigger_name | ALL | USER ]` + /// + /// Note: this is a PostgreSQL-specific operation. + EnableTrigger { + name: Ident, + }, + /// `ENABLE RULE rewrite_rule_name` + /// + /// Note: this is a PostgreSQL-specific operation. + EnableRule { + name: Ident, + }, + /// `ENABLE ROW LEVEL SECURITY` + /// + /// Note: this is a PostgreSQL-specific operation. + EnableRowLevelSecurity, + /// `ENABLE REPLICA TRIGGER trigger_name` + /// + /// Note: this is a PostgreSQL-specific operation. + EnableReplicaTrigger { + name: Ident, + }, + /// `ENABLE ALWAYS TRIGGER trigger_name` + /// + /// Note: this is a PostgreSQL-specific operation. + EnableAlwaysTrigger { + name: Ident, + }, + /// `ENABLE REPLICA RULE rewrite_rule_name` + /// + /// Note: this is a PostgreSQL-specific operation. + EnableReplicaRule { + name: Ident, + }, + /// `ENABLE ALWAYS RULE rewrite_rule_name` + /// + /// Note: this is a PostgreSQL-specific operation. + EnableAlwaysRule { + name: Ident, + }, /// `RENAME TO PARTITION (partition=val)` RenamePartitions { old_partitions: Vec, @@ -93,7 +134,9 @@ pub enum AlterTableOperation { new_column_name: Ident, }, /// `RENAME TO ` - RenameTable { table_name: ObjectName }, + RenameTable { + table_name: ObjectName, + }, // CHANGE [ COLUMN ] [ ] ChangeColumn { old_name: Ident, @@ -104,7 +147,10 @@ pub enum AlterTableOperation { /// `RENAME CONSTRAINT TO ` /// /// Note: this is a PostgreSQL-specific operation. - RenameConstraint { old_name: Ident, new_name: Ident }, + RenameConstraint { + old_name: Ident, + new_name: Ident, + }, /// `ALTER [ COLUMN ]` AlterColumn { column_name: Ident, @@ -113,7 +159,9 @@ pub enum AlterTableOperation { /// 'SWAP WITH ' /// /// Note: this is Snowflake specific - SwapWith { table_name: ObjectName }, + SwapWith { + table_name: ObjectName, + }, } #[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)] @@ -198,6 +246,27 @@ impl fmt::Display for AlterTableOperation { column_name, if *cascade { " CASCADE" } else { "" } ), + AlterTableOperation::EnableTrigger { name } => { + write!(f, "ENABLE TRIGGER {name}") + } + AlterTableOperation::EnableRule { name } => { + write!(f, "ENABLE RULE {name}") + } + AlterTableOperation::EnableRowLevelSecurity => { + write!(f, "ENABLE ROW LEVEL SECURITY") + } + AlterTableOperation::EnableReplicaTrigger { name } => { + write!(f, "ENABLE REPLICA TRIGGER {name}") + } + AlterTableOperation::EnableAlwaysTrigger { name } => { + write!(f, "ENABLE ALWAYS TRIGGER {name}") + } + AlterTableOperation::EnableReplicaRule { name } => { + write!(f, "ENABLE REPLICA RULE {name}") + } + AlterTableOperation::EnableAlwaysRule { name } => { + write!(f, "ENABLE ALWAYS RULE {name}") + } AlterTableOperation::RenamePartitions { old_partitions, new_partitions, diff --git a/src/keywords.rs b/src/keywords.rs index 24750ef56..eb3d74f67 100644 --- a/src/keywords.rs +++ b/src/keywords.rs @@ -241,6 +241,7 @@ define_keywords!( ELEMENTS, ELSE, EMPTY, + ENABLE, ENCODING, ENCRYPTION, END, @@ -538,6 +539,7 @@ define_keywords!( REPAIR, REPEATABLE, REPLACE, + REPLICA, REPLICATION, RESET, RESPECT, @@ -567,6 +569,7 @@ define_keywords!( SCROLL, SEARCH, SECOND, + SECURITY, SELECT, SEMI, SENSITIVE, diff --git a/src/parser/mod.rs b/src/parser/mod.rs index c0d308e79..2146cd790 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -4638,17 +4638,12 @@ impl<'a> Parser<'a> { } } else if self.parse_keyword(Keyword::DISABLE) { if self.parse_keyword(Keyword::TRIGGER) { - // let all = self.parse_keyword(Keyword::ALL); - // let user = self.parse_keyword(Keyword::ALL); let name = self.parse_identifier()?; - - // println!("parse all: {}", all); - AlterTableOperation::DisableTrigger { name } } else if self.parse_keyword(Keyword::RULE) { let name = self.parse_identifier()?; AlterTableOperation::DisableRule { name } - } else if self.parse_keyword(Keyword::ROW) { + } else if self.parse_keywords(&[Keyword::ROW, Keyword::LEVEL, Keyword::SECURITY]) { AlterTableOperation::DisableRowLevelSecurity {} } else { return self.expected( @@ -4656,6 +4651,33 @@ impl<'a> Parser<'a> { self.peek_token(), ); } + } else if self.parse_keyword(Keyword::ENABLE) { + if self.parse_keyword(Keyword::TRIGGER) { + let name = self.parse_identifier()?; + AlterTableOperation::EnableTrigger { name } + } else if self.parse_keyword(Keyword::RULE) { + let name = self.parse_identifier()?; + AlterTableOperation::EnableRule { name } + } else if self.parse_keywords(&[Keyword::ROW, Keyword::LEVEL, Keyword::SECURITY]) { + AlterTableOperation::EnableRowLevelSecurity {} + } else if self.parse_keywords(&[Keyword::REPLICA, Keyword::RULE]) { + let name = self.parse_identifier()?; + AlterTableOperation::EnableReplicaRule { name } + } else if self.parse_keywords(&[Keyword::ALWAYS, Keyword::RULE]) { + let name = self.parse_identifier()?; + AlterTableOperation::EnableAlwaysRule { name } + } else if self.parse_keywords(&[Keyword::REPLICA, Keyword::TRIGGER]) { + let name = self.parse_identifier()?; + AlterTableOperation::EnableReplicaTrigger { name } + } else if self.parse_keywords(&[Keyword::ALWAYS, Keyword::TRIGGER]) { + let name = self.parse_identifier()?; + AlterTableOperation::EnableAlwaysTrigger { name } + } else { + return self.expected( + "TRIGGER, RULE or ROW LEVEL SECURITY after ENABLE", + self.peek_token(), + ); + } } else if self.parse_keyword(Keyword::DROP) { if self.parse_keywords(&[Keyword::IF, Keyword::EXISTS, Keyword::PARTITION]) { self.expect_token(&Token::LParen)?; diff --git a/tests/sqlparser_postgres.rs b/tests/sqlparser_postgres.rs index 56f791a38..24a2ccb60 100644 --- a/tests/sqlparser_postgres.rs +++ b/tests/sqlparser_postgres.rs @@ -564,12 +564,26 @@ fn parse_alter_table_constraints_rename() { } #[test] -fn parse_alter_table_disable_trigger() { +fn parse_alter_table_disable() { pg_and_generic().verified_stmt("ALTER TABLE tab DISABLE TRIGGER ALL"); pg_and_generic().verified_stmt("ALTER TABLE tab DISABLE TRIGGER USER"); pg_and_generic().verified_stmt("ALTER TABLE tab DISABLE TRIGGER trigger_name"); + pg_and_generic().verified_stmt("ALTER TABLE tab DISABLE RULE rule_name"); + pg_and_generic().verified_stmt("ALTER TABLE tab DISABLE ROW LEVEL SECURITY"); } +#[test] +fn parse_alter_table_enable() { + pg_and_generic().verified_stmt("ALTER TABLE tab ENABLE TRIGGER ALL"); + pg_and_generic().verified_stmt("ALTER TABLE tab ENABLE TRIGGER USER"); + pg_and_generic().verified_stmt("ALTER TABLE tab ENABLE TRIGGER trigger_name"); + pg_and_generic().verified_stmt("ALTER TABLE tab ENABLE RULE rule_name"); + pg_and_generic().verified_stmt("ALTER TABLE tab ENABLE ROW LEVEL SECURITY"); + pg_and_generic().verified_stmt("ALTER TABLE tab ENABLE REPLICA TRIGGER trigger_name"); + pg_and_generic().verified_stmt("ALTER TABLE tab ENABLE ALWAYS TRIGGER trigger_name"); + pg_and_generic().verified_stmt("ALTER TABLE tab ENABLE REPLICA RULE rule_name"); + pg_and_generic().verified_stmt("ALTER TABLE tab ENABLE ALWAYS rule_name"); +} #[test] fn parse_alter_table_alter_column() { pg().one_statement_parses_to( From 5b7bd43e8bf9c14b62e97e3773bf7112c865c8ac Mon Sep 17 00:00:00 2001 From: Toby Hede Date: Sat, 30 Dec 2023 14:42:31 +1100 Subject: [PATCH 3/4] Alphabetise --- src/ast/ddl.rs | 102 +++++++++++++++--------------------- src/parser/mod.rs | 32 +++++------ tests/sqlparser_postgres.rs | 16 +++--- 3 files changed, 65 insertions(+), 85 deletions(-) diff --git a/src/ast/ddl.rs b/src/ast/ddl.rs index c57bce6aa..cd0cf1797 100644 --- a/src/ast/ddl.rs +++ b/src/ast/ddl.rs @@ -45,18 +45,18 @@ pub enum AlterTableOperation { /// . column_def: ColumnDef, }, - /// DISABLE TRIGGER [ trigger_name | ALL | USER ] - /// DISABLE RULE rewrite_rule_name - /// DISABLE ROW LEVEL SECURITY + /// `DISABLE ROW LEVEL SECURITY` /// /// Note: this is a PostgreSQL-specific operation. - DisableTrigger { - name: Ident, - }, - DisableRule { - name: Ident, - }, DisableRowLevelSecurity, + /// `DISABLE RULE rewrite_rule_name` + /// + /// Note: this is a PostgreSQL-specific operation. + DisableRule { name: Ident }, + /// `DISABLE TRIGGER [ trigger_name | ALL | USER ]` + /// + /// Note: this is a PostgreSQL-specific operation. + DisableTrigger { name: Ident }, /// `DROP CONSTRAINT [ IF EXISTS ] ` DropConstraint { if_exists: bool, @@ -73,47 +73,34 @@ pub enum AlterTableOperation { /// /// Note: this is a MySQL-specific operation. DropPrimaryKey, - - /// `ENABLE TRIGGER [ trigger_name | ALL | USER ]` + /// `ENABLE ALWAYS RULE rewrite_rule_name` /// /// Note: this is a PostgreSQL-specific operation. - EnableTrigger { - name: Ident, - }, - /// `ENABLE RULE rewrite_rule_name` + EnableAlwaysRule { name: Ident }, + /// `ENABLE ALWAYS TRIGGER trigger_name` /// /// Note: this is a PostgreSQL-specific operation. - EnableRule { - name: Ident, - }, - /// `ENABLE ROW LEVEL SECURITY` + EnableAlwaysTrigger { name: Ident }, + /// `ENABLE REPLICA RULE rewrite_rule_name` /// /// Note: this is a PostgreSQL-specific operation. - EnableRowLevelSecurity, + EnableReplicaRule { name: Ident }, /// `ENABLE REPLICA TRIGGER trigger_name` /// /// Note: this is a PostgreSQL-specific operation. - EnableReplicaTrigger { - name: Ident, - }, - /// `ENABLE ALWAYS TRIGGER trigger_name` + EnableReplicaTrigger { name: Ident }, + /// `ENABLE ROW LEVEL SECURITY` /// /// Note: this is a PostgreSQL-specific operation. - EnableAlwaysTrigger { - name: Ident, - }, - /// `ENABLE REPLICA RULE rewrite_rule_name` + EnableRowLevelSecurity, + /// `ENABLE RULE rewrite_rule_name` /// /// Note: this is a PostgreSQL-specific operation. - EnableReplicaRule { - name: Ident, - }, - /// `ENABLE ALWAYS RULE rewrite_rule_name` + EnableRule { name: Ident }, + /// `ENABLE TRIGGER [ trigger_name | ALL | USER ]` /// /// Note: this is a PostgreSQL-specific operation. - EnableAlwaysRule { - name: Ident, - }, + EnableTrigger { name: Ident }, /// `RENAME TO PARTITION (partition=val)` RenamePartitions { old_partitions: Vec, @@ -134,9 +121,7 @@ pub enum AlterTableOperation { new_column_name: Ident, }, /// `RENAME TO ` - RenameTable { - table_name: ObjectName, - }, + RenameTable { table_name: ObjectName }, // CHANGE [ COLUMN ] [ ] ChangeColumn { old_name: Ident, @@ -147,10 +132,7 @@ pub enum AlterTableOperation { /// `RENAME CONSTRAINT TO ` /// /// Note: this is a PostgreSQL-specific operation. - RenameConstraint { - old_name: Ident, - new_name: Ident, - }, + RenameConstraint { old_name: Ident, new_name: Ident }, /// `ALTER [ COLUMN ]` AlterColumn { column_name: Ident, @@ -159,9 +141,7 @@ pub enum AlterTableOperation { /// 'SWAP WITH ' /// /// Note: this is Snowflake specific - SwapWith { - table_name: ObjectName, - }, + SwapWith { table_name: ObjectName }, } #[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)] @@ -203,14 +183,14 @@ impl fmt::Display for AlterTableOperation { AlterTableOperation::AlterColumn { column_name, op } => { write!(f, "ALTER COLUMN {column_name} {op}") } - AlterTableOperation::DisableTrigger { name } => { - write!(f, "DISABLE TRIGGER {name}") + AlterTableOperation::DisableRowLevelSecurity => { + write!(f, "DISABLE ROW LEVEL SECURITY") } AlterTableOperation::DisableRule { name } => { write!(f, "DISABLE RULE {name}") } - AlterTableOperation::DisableRowLevelSecurity => { - write!(f, "DISABLE ROW LEVEL SECURITY") + AlterTableOperation::DisableTrigger { name } => { + write!(f, "DISABLE TRIGGER {name}") } AlterTableOperation::DropPartitions { partitions, @@ -246,26 +226,26 @@ impl fmt::Display for AlterTableOperation { column_name, if *cascade { " CASCADE" } else { "" } ), - AlterTableOperation::EnableTrigger { name } => { - write!(f, "ENABLE TRIGGER {name}") + AlterTableOperation::EnableAlwaysRule { name } => { + write!(f, "ENABLE ALWAYS RULE {name}") } - AlterTableOperation::EnableRule { name } => { - write!(f, "ENABLE RULE {name}") + AlterTableOperation::EnableAlwaysTrigger { name } => { + write!(f, "ENABLE ALWAYS TRIGGER {name}") } - AlterTableOperation::EnableRowLevelSecurity => { - write!(f, "ENABLE ROW LEVEL SECURITY") + AlterTableOperation::EnableReplicaRule { name } => { + write!(f, "ENABLE REPLICA RULE {name}") } AlterTableOperation::EnableReplicaTrigger { name } => { write!(f, "ENABLE REPLICA TRIGGER {name}") } - AlterTableOperation::EnableAlwaysTrigger { name } => { - write!(f, "ENABLE ALWAYS TRIGGER {name}") + AlterTableOperation::EnableRowLevelSecurity => { + write!(f, "ENABLE ROW LEVEL SECURITY") } - AlterTableOperation::EnableReplicaRule { name } => { - write!(f, "ENABLE REPLICA RULE {name}") + AlterTableOperation::EnableRule { name } => { + write!(f, "ENABLE RULE {name}") } - AlterTableOperation::EnableAlwaysRule { name } => { - write!(f, "ENABLE ALWAYS RULE {name}") + AlterTableOperation::EnableTrigger { name } => { + write!(f, "ENABLE TRIGGER {name}") } AlterTableOperation::RenamePartitions { old_partitions, diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 2146cd790..df3370c73 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -4637,44 +4637,44 @@ impl<'a> Parser<'a> { } } } else if self.parse_keyword(Keyword::DISABLE) { - if self.parse_keyword(Keyword::TRIGGER) { - let name = self.parse_identifier()?; - AlterTableOperation::DisableTrigger { name } + if self.parse_keywords(&[Keyword::ROW, Keyword::LEVEL, Keyword::SECURITY]) { + AlterTableOperation::DisableRowLevelSecurity {} } else if self.parse_keyword(Keyword::RULE) { let name = self.parse_identifier()?; AlterTableOperation::DisableRule { name } - } else if self.parse_keywords(&[Keyword::ROW, Keyword::LEVEL, Keyword::SECURITY]) { - AlterTableOperation::DisableRowLevelSecurity {} + } else if self.parse_keyword(Keyword::TRIGGER) { + let name = self.parse_identifier()?; + AlterTableOperation::DisableTrigger { name } } else { return self.expected( - "TRIGGER, RULE or ROW LEVEL SECURITY after DISABLE", + "ROW LEVEL SECURITY, RULE, or TRIGGER after DISABLE", self.peek_token(), ); } } else if self.parse_keyword(Keyword::ENABLE) { - if self.parse_keyword(Keyword::TRIGGER) { + if self.parse_keywords(&[Keyword::ALWAYS, Keyword::RULE]) { let name = self.parse_identifier()?; - AlterTableOperation::EnableTrigger { name } - } else if self.parse_keyword(Keyword::RULE) { + AlterTableOperation::EnableAlwaysRule { name } + } else if self.parse_keywords(&[Keyword::ALWAYS, Keyword::TRIGGER]) { let name = self.parse_identifier()?; - AlterTableOperation::EnableRule { name } + AlterTableOperation::EnableAlwaysTrigger { name } } else if self.parse_keywords(&[Keyword::ROW, Keyword::LEVEL, Keyword::SECURITY]) { AlterTableOperation::EnableRowLevelSecurity {} } else if self.parse_keywords(&[Keyword::REPLICA, Keyword::RULE]) { let name = self.parse_identifier()?; AlterTableOperation::EnableReplicaRule { name } - } else if self.parse_keywords(&[Keyword::ALWAYS, Keyword::RULE]) { - let name = self.parse_identifier()?; - AlterTableOperation::EnableAlwaysRule { name } } else if self.parse_keywords(&[Keyword::REPLICA, Keyword::TRIGGER]) { let name = self.parse_identifier()?; AlterTableOperation::EnableReplicaTrigger { name } - } else if self.parse_keywords(&[Keyword::ALWAYS, Keyword::TRIGGER]) { + } else if self.parse_keyword(Keyword::RULE) { let name = self.parse_identifier()?; - AlterTableOperation::EnableAlwaysTrigger { name } + AlterTableOperation::EnableRule { name } + } else if self.parse_keyword(Keyword::TRIGGER) { + let name = self.parse_identifier()?; + AlterTableOperation::EnableTrigger { name } } else { return self.expected( - "TRIGGER, RULE or ROW LEVEL SECURITY after ENABLE", + "ALWAYS, REPLICA, ROW LEVEL SECURITY, RULE, or TRIGGER after ENABLE", self.peek_token(), ); } diff --git a/tests/sqlparser_postgres.rs b/tests/sqlparser_postgres.rs index 24a2ccb60..5adcb43a5 100644 --- a/tests/sqlparser_postgres.rs +++ b/tests/sqlparser_postgres.rs @@ -565,24 +565,24 @@ fn parse_alter_table_constraints_rename() { #[test] fn parse_alter_table_disable() { + pg_and_generic().verified_stmt("ALTER TABLE tab DISABLE ROW LEVEL SECURITY"); + pg_and_generic().verified_stmt("ALTER TABLE tab DISABLE RULE rule_name"); pg_and_generic().verified_stmt("ALTER TABLE tab DISABLE TRIGGER ALL"); pg_and_generic().verified_stmt("ALTER TABLE tab DISABLE TRIGGER USER"); pg_and_generic().verified_stmt("ALTER TABLE tab DISABLE TRIGGER trigger_name"); - pg_and_generic().verified_stmt("ALTER TABLE tab DISABLE RULE rule_name"); - pg_and_generic().verified_stmt("ALTER TABLE tab DISABLE ROW LEVEL SECURITY"); } #[test] fn parse_alter_table_enable() { + pg_and_generic().verified_stmt("ALTER TABLE tab ENABLE ALWAYS RULE rule_name"); + pg_and_generic().verified_stmt("ALTER TABLE tab ENABLE ALWAYS TRIGGER trigger_name"); + pg_and_generic().verified_stmt("ALTER TABLE tab ENABLE REPLICA TRIGGER trigger_name"); + pg_and_generic().verified_stmt("ALTER TABLE tab ENABLE REPLICA RULE rule_name"); + pg_and_generic().verified_stmt("ALTER TABLE tab ENABLE ROW LEVEL SECURITY"); + pg_and_generic().verified_stmt("ALTER TABLE tab ENABLE RULE rule_name"); pg_and_generic().verified_stmt("ALTER TABLE tab ENABLE TRIGGER ALL"); pg_and_generic().verified_stmt("ALTER TABLE tab ENABLE TRIGGER USER"); pg_and_generic().verified_stmt("ALTER TABLE tab ENABLE TRIGGER trigger_name"); - pg_and_generic().verified_stmt("ALTER TABLE tab ENABLE RULE rule_name"); - pg_and_generic().verified_stmt("ALTER TABLE tab ENABLE ROW LEVEL SECURITY"); - pg_and_generic().verified_stmt("ALTER TABLE tab ENABLE REPLICA TRIGGER trigger_name"); - pg_and_generic().verified_stmt("ALTER TABLE tab ENABLE ALWAYS TRIGGER trigger_name"); - pg_and_generic().verified_stmt("ALTER TABLE tab ENABLE REPLICA RULE rule_name"); - pg_and_generic().verified_stmt("ALTER TABLE tab ENABLE ALWAYS rule_name"); } #[test] fn parse_alter_table_alter_column() { From fc350137b0a70f33e19f07788292b7dcb9fd2e0f Mon Sep 17 00:00:00 2001 From: Toby Hede Date: Sat, 30 Dec 2023 17:34:02 +1100 Subject: [PATCH 4/4] Fix clippy issues Signed-off-by: Toby Hede --- .tool-versions | 2 +- src/dialect/mod.rs | 1 + src/tokenizer.rs | 7 ++----- tests/sqlparser_postgres.rs | 2 +- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/.tool-versions b/.tool-versions index d090dbab8..6c98ab3f5 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1 +1 @@ -rust 1.73.0 \ No newline at end of file +rust 1.75.0 \ No newline at end of file diff --git a/src/dialect/mod.rs b/src/dialect/mod.rs index eab30ccd2..5167be249 100644 --- a/src/dialect/mod.rs +++ b/src/dialect/mod.rs @@ -349,6 +349,7 @@ mod tests { } } + #[allow(clippy::needless_raw_string_hashes)] let statement = r#"SELECT 'Wayne\'s World'"#; let res1 = Parser::parse_sql(&MySqlDialect {}, statement); let res2 = Parser::parse_sql(&WrappedDialect(MySqlDialect {}), statement); diff --git a/src/tokenizer.rs b/src/tokenizer.rs index 0400b21c5..e2d1843bc 100644 --- a/src/tokenizer.rs +++ b/src/tokenizer.rs @@ -727,10 +727,7 @@ impl<'a> Tokenizer<'a> { // match binary literal that starts with 0x if s == "0" && chars.peek() == Some(&'x') { chars.next(); - let s2 = peeking_take_while( - chars, - |ch| matches!(ch, '0'..='9' | 'A'..='F' | 'a'..='f'), - ); + let s2 = peeking_take_while(chars, |ch| ch.is_ascii_hexdigit()); return Ok(Some(Token::HexStringLiteral(s2))); } @@ -1077,7 +1074,7 @@ impl<'a> Tokenizer<'a> { match chars.peek() { Some('$') => { chars.next(); - for (_, c) in value.chars().enumerate() { + for c in value.chars() { let next_char = chars.next(); if Some(c) != next_char { return self.tokenizer_error( diff --git a/tests/sqlparser_postgres.rs b/tests/sqlparser_postgres.rs index 5adcb43a5..0c1463f92 100644 --- a/tests/sqlparser_postgres.rs +++ b/tests/sqlparser_postgres.rs @@ -3277,7 +3277,7 @@ fn parse_dollar_quoted_string() { let stmt = pg().parse_sql_statements(sql).unwrap(); - let projection = match stmt.get(0).unwrap() { + let projection = match stmt.first().unwrap() { Statement::Query(query) => match &*query.body { SetExpr::Select(select) => &select.projection, _ => unreachable!(),