Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions fuzz/fuzz_seeds/postgres_alter_extension.sql
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ ALTER EXTENSION citext ADD ROUTINE public.r(int);
ALTER EXTENSION citext DROP AGGREGATE agg(int ORDER BY text);
ALTER EXTENSION citext ADD AGGREGATE cnt(*);
ALTER EXTENSION citext ADD OPERATOR - (NONE, int);
ALTER EXTENSION citext DROP OPERATOR CLASS oc USING btree;
10 changes: 10 additions & 0 deletions src/ast/ddl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4963,6 +4963,13 @@ pub enum AlterExtensionMember {
MaterializedView(ObjectName),
/// `OPERATOR operator_name (left_type, right_type)`
Operator(DropOperatorSignature),
/// `OPERATOR CLASS object_name USING index_method`
OperatorClass {
/// Operator class name.
name: ObjectName,
/// Index method.
using: Ident,
},
/// `PROCEDURE procedure_name [ ( [ [ argmode ] [ argname ] argtype [, ...] ] ) ]`
Procedure(FunctionDesc),
/// `PUBLICATION object_name`
Expand Down Expand Up @@ -5041,6 +5048,9 @@ impl fmt::Display for AlterExtensionMember {
}
AlterExtensionMember::MaterializedView(name) => write!(f, "MATERIALIZED VIEW {name}"),
AlterExtensionMember::Operator(signature) => write!(f, "OPERATOR {signature}"),
AlterExtensionMember::OperatorClass { name, using } => {
write!(f, "OPERATOR CLASS {name} USING {using}")
}
AlterExtensionMember::Procedure(function) => write!(f, "PROCEDURE {function}"),
AlterExtensionMember::Publication(name) => write!(f, "PUBLICATION {name}"),
AlterExtensionMember::Routine(function) => write!(f, "ROUTINE {function}"),
Expand Down
13 changes: 10 additions & 3 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12577,9 +12577,16 @@ impl<'a> Parser<'a> {
self.parse_object_name(false)?,
))
} else if self.parse_keyword(Keyword::OPERATOR) {
Ok(AlterExtensionMember::Operator(
self.parse_drop_operator_signature()?,
))
if self.parse_keyword(Keyword::CLASS) {
let name = self.parse_object_name(false)?;
self.expect_keyword_is(Keyword::USING)?;
let using = self.parse_identifier()?;
Ok(AlterExtensionMember::OperatorClass { name, using })
} else {
Ok(AlterExtensionMember::Operator(
self.parse_drop_operator_signature()?,
))
}
} else if self.parse_keyword(Keyword::PROCEDURE) {
Ok(AlterExtensionMember::Procedure(self.parse_function_desc()?))
} else if self.parse_keyword(Keyword::PUBLICATION) {
Expand Down
13 changes: 13 additions & 0 deletions tests/sqlparser_postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13560,6 +13560,7 @@ fn alter_extension_member_round_trip_forms(action: &str) {
format!("ALTER EXTENSION ext_name {action} MATERIALIZED VIEW mv"),
format!("ALTER EXTENSION ext_name {action} OPERATOR + (INT, TEXT)"),
format!("ALTER EXTENSION ext_name {action} OPERATOR - (NONE, INT)"),
format!("ALTER EXTENSION ext_name {action} OPERATOR CLASS oc USING btree"),
format!("ALTER EXTENSION ext_name {action} PROCEDURE p"),
format!("ALTER EXTENSION ext_name {action} PROCEDURE p()"),
format!("ALTER EXTENSION ext_name {action} PROCEDURE p(INT)"),
Expand Down Expand Up @@ -13809,6 +13810,18 @@ fn parse_alter_extension_add_member() {
"ALTER EXTENSION ext_name ADD OPERATOR +",
"Expected: (, found: EOF",
),
(
"ALTER EXTENSION ext_name ADD OPERATOR CLASS oc",
"Expected: USING, found: EOF",
),
(
"ALTER EXTENSION ext_name ADD OPERATOR CLASS oc USING",
"Expected: identifier, found: EOF",
),
(
"ALTER EXTENSION ext_name ADD OPERATOR CLASS",
"Expected: identifier, found: EOF",
),
] {
assert_eq!(
pg_and_generic().parse_sql_statements(sql).unwrap_err(),
Expand Down
Loading