PostgreSQL: Support `ALTER DATABASE ... REFRESH COLLATION VERSION`
diff --git a/fuzz/fuzz_seeds/alter_database.sql b/fuzz/fuzz_seeds/alter_database.sql index aeb843d..7b69441 100644 --- a/fuzz/fuzz_seeds/alter_database.sql +++ b/fuzz/fuzz_seeds/alter_database.sql
@@ -4,4 +4,5 @@ ALTER DATABASE d SET XML OPTION DOCUMENT; ALTER DATABASE d RESET ALL; ALTER DATABASE d OWNER TO CURRENT_USER; -ALTER DATABASE d SET TABLESPACE pg_default +ALTER DATABASE d SET TABLESPACE pg_default; +ALTER DATABASE d REFRESH COLLATION VERSION
diff --git a/src/ast/ddl.rs b/src/ast/ddl.rs index 2573c09..bc31ad9 100644 --- a/src/ast/ddl.rs +++ b/src/ast/ddl.rs
@@ -5037,6 +5037,8 @@ /// Target tablespace name. tablespace_name: Ident, }, + /// `REFRESH COLLATION VERSION` + RefreshCollationVersion, } impl fmt::Display for AlterDatabaseOperation { @@ -5052,6 +5054,9 @@ AlterDatabaseOperation::SetTablespace { tablespace_name } => { write!(f, "SET TABLESPACE {tablespace_name}") } + AlterDatabaseOperation::RefreshCollationVersion => { + f.write_str("REFRESH COLLATION VERSION") + } } } }
diff --git a/src/parser/mod.rs b/src/parser/mod.rs index dc8e8ad..fa727c2 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs
@@ -12522,9 +12522,11 @@ }) } else if self.parse_keywords(&[Keyword::OWNER, Keyword::TO]) { AlterDatabaseOperation::OwnerTo(self.parse_owner()?) + } else if self.parse_keywords(&[Keyword::REFRESH, Keyword::COLLATION, Keyword::VERSION]) { + AlterDatabaseOperation::RefreshCollationVersion } else { return self.expected_ref( - "RENAME TO, OWNER TO, SET or RESET after ALTER DATABASE", + "RENAME TO, OWNER TO, SET, RESET or REFRESH COLLATION VERSION after ALTER DATABASE", self.peek_token_ref(), ); };
diff --git a/tests/sqlparser_postgres.rs b/tests/sqlparser_postgres.rs index c92788b..3b8b8fc 100644 --- a/tests/sqlparser_postgres.rs +++ b/tests/sqlparser_postgres.rs
@@ -13555,7 +13555,7 @@ ), ( "ALTER DATABASE d", - "Expected: RENAME TO, OWNER TO, SET or RESET after ALTER DATABASE, found: EOF", + "Expected: RENAME TO, OWNER TO, SET, RESET or REFRESH COLLATION VERSION after ALTER DATABASE, found: EOF", ), ] { assert_eq!( @@ -13764,3 +13764,21 @@ ParserError::ParserError("Expected: identifier, found: EOF".to_string()) ); } + +#[test] +fn parse_alter_database_refresh_collation_version() { + let dialects = pg_and_generic(); + assert_eq!( + dialects.verified_stmt("ALTER DATABASE d REFRESH COLLATION VERSION"), + Statement::AlterDatabase(AlterDatabase { + name: ObjectName::from(vec![Ident::new("d")]), + operation: AlterDatabaseOperation::RefreshCollationVersion, + }) + ); + assert_eq!( + dialects + .parse_sql_statements("ALTER DATABASE d REFRESH COLLATION VERSION x") + .unwrap_err(), + ParserError::ParserError("Expected: end of statement, found: x".to_string()) + ); +}