PostgreSQL: Support `ALTER DATABASE ... RESET`
diff --git a/fuzz/fuzz_seeds/alter_database.sql b/fuzz/fuzz_seeds/alter_database.sql index 228a0bc..18a9cee 100644 --- a/fuzz/fuzz_seeds/alter_database.sql +++ b/fuzz/fuzz_seeds/alter_database.sql
@@ -1,4 +1,5 @@ ALTER DATABASE d RENAME TO "Weird"; ALTER DATABASE d SET search_path TO "$user", public; ALTER DATABASE d SET TIME ZONE 'Asia/Tokyo'; -ALTER DATABASE d SET XML OPTION DOCUMENT +ALTER DATABASE d SET XML OPTION DOCUMENT; +ALTER DATABASE d RESET ALL
diff --git a/src/ast/ddl.rs b/src/ast/ddl.rs index b2d8fde..31c9371 100644 --- a/src/ast/ddl.rs +++ b/src/ast/ddl.rs
@@ -5028,6 +5028,8 @@ }, /// `SET ...`, stored as the database's default for a configuration parameter. Set(ConfigurationSet), + /// `RESET configuration_parameter` or `RESET ALL` + Reset(ResetConfig), } impl fmt::Display for AlterDatabaseOperation { @@ -5035,6 +5037,10 @@ match self { AlterDatabaseOperation::RenameTo { new_name } => write!(f, "RENAME TO {new_name}"), AlterDatabaseOperation::Set(set) => write!(f, "{set}"), + AlterDatabaseOperation::Reset(ResetConfig::ALL) => f.write_str("RESET ALL"), + AlterDatabaseOperation::Reset(ResetConfig::ConfigName(name)) => { + write!(f, "RESET {name}") + } } } }
diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 4bb2480..546bf01 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs
@@ -12508,9 +12508,15 @@ } } else if self.parse_keyword(Keyword::SET) { AlterDatabaseOperation::Set(self.parse_configuration_set()?) + } else if self.parse_keyword(Keyword::RESET) { + AlterDatabaseOperation::Reset(if self.parse_keyword(Keyword::ALL) { + ResetConfig::ALL + } else { + ResetConfig::ConfigName(self.parse_object_name(false)?) + }) } else { return self.expected_ref( - "RENAME TO or SET after ALTER DATABASE", + "RENAME TO, SET or RESET after ALTER DATABASE", self.peek_token_ref(), ); };
diff --git a/tests/sqlparser_postgres.rs b/tests/sqlparser_postgres.rs index ed9667d..6236753 100644 --- a/tests/sqlparser_postgres.rs +++ b/tests/sqlparser_postgres.rs
@@ -13555,7 +13555,7 @@ ), ( "ALTER DATABASE d", - "Expected: RENAME TO or SET after ALTER DATABASE, found: EOF", + "Expected: RENAME TO, SET or RESET after ALTER DATABASE, found: EOF", ), ] { assert_eq!( @@ -13682,3 +13682,30 @@ ); } } + +#[test] +fn parse_alter_database_reset() { + let dialects = pg_and_generic(); + assert_eq!( + dialects.verified_stmt("ALTER DATABASE d RESET my.custom"), + Statement::AlterDatabase(AlterDatabase { + name: ObjectName::from(vec![Ident::new("d")]), + operation: AlterDatabaseOperation::Reset(ResetConfig::ConfigName(ObjectName::from( + vec![Ident::new("my"), Ident::new("custom")] + ))), + }) + ); + assert_eq!( + dialects.verified_stmt("ALTER DATABASE d RESET ALL"), + Statement::AlterDatabase(AlterDatabase { + name: ObjectName::from(vec![Ident::new("d")]), + operation: AlterDatabaseOperation::Reset(ResetConfig::ALL), + }) + ); + assert_eq!( + dialects + .parse_sql_statements("ALTER DATABASE d RESET") + .unwrap_err(), + ParserError::ParserError("Expected: identifier, found: EOF".to_string()) + ); +}