Added support for DROP OPERATOR CLASS syntax (#2109)
Some checks are pending
license / Release Audit Tool (RAT) (push) Waiting to run
Rust / lint (push) Waiting to run
Rust / benchmark-lint (push) Waiting to run
Rust / compile (push) Waiting to run
Rust / docs (push) Waiting to run
Rust / codestyle (push) Waiting to run
Rust / compile-no-std (push) Waiting to run
Rust / test (beta) (push) Waiting to run
Rust / test (nightly) (push) Waiting to run
Rust / test (stable) (push) Waiting to run

This commit is contained in:
Luca Cappelletti 2025-12-01 16:09:52 +01:00 committed by GitHub
parent 89938b9fcb
commit 367aa6e8d0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 160 additions and 13 deletions

View file

@ -4288,3 +4288,40 @@ impl Spanned for DropOperatorFamily {
Span::empty()
}
}
/// `DROP OPERATOR CLASS` statement
/// See <https://www.postgresql.org/docs/current/sql-dropopclass.html>
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
pub struct DropOperatorClass {
/// `IF EXISTS` clause
pub if_exists: bool,
/// One or more operator classes to drop
pub names: Vec<ObjectName>,
/// Index method (btree, hash, gist, gin, etc.)
pub using: Ident,
/// `CASCADE or RESTRICT`
pub drop_behavior: Option<DropBehavior>,
}
impl fmt::Display for DropOperatorClass {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "DROP OPERATOR CLASS")?;
if self.if_exists {
write!(f, " IF EXISTS")?;
}
write!(f, " {}", display_comma_separated(&self.names))?;
write!(f, " USING {}", self.using)?;
if let Some(drop_behavior) = &self.drop_behavior {
write!(f, " {}", drop_behavior)?;
}
Ok(())
}
}
impl Spanned for DropOperatorClass {
fn span(&self) -> Span {
Span::empty()
}
}

View file

@ -67,7 +67,7 @@ pub use self::ddl::{
ColumnPolicyProperty, ConstraintCharacteristics, CreateConnector, CreateDomain,
CreateExtension, CreateFunction, CreateIndex, CreateOperator, CreateOperatorClass,
CreateOperatorFamily, CreateTable, CreateTrigger, CreateView, Deduplicate, DeferrableInitial,
DropBehavior, DropExtension, DropFunction, DropOperator, DropOperatorFamily,
DropBehavior, DropExtension, DropFunction, DropOperator, DropOperatorClass, DropOperatorFamily,
DropOperatorSignature, DropTrigger, GeneratedAs, GeneratedExpressionMode, IdentityParameters,
IdentityProperty, IdentityPropertyFormatKind, IdentityPropertyKind, IdentityPropertyOrder,
IndexColumn, IndexOption, IndexType, KeyOrIndexDisplay, Msck, NullsDistinctOption,
@ -3586,6 +3586,12 @@ pub enum Statement {
/// <https://www.postgresql.org/docs/current/sql-dropopfamily.html>
DropOperatorFamily(DropOperatorFamily),
/// ```sql
/// DROP OPERATOR CLASS [ IF EXISTS ] name USING index_method [ CASCADE | RESTRICT ]
/// ```
/// Note: this is a PostgreSQL-specific statement.
/// <https://www.postgresql.org/docs/current/sql-dropopclass.html>
DropOperatorClass(DropOperatorClass),
/// ```sql
/// FETCH
/// ```
/// Retrieve rows from a query using a cursor
@ -4853,6 +4859,9 @@ impl fmt::Display for Statement {
Statement::DropOperatorFamily(drop_operator_family) => {
write!(f, "{drop_operator_family}")
}
Statement::DropOperatorClass(drop_operator_class) => {
write!(f, "{drop_operator_class}")
}
Statement::CreateRole(create_role) => write!(f, "{create_role}"),
Statement::CreateSecret {
or_replace,

View file

@ -377,6 +377,7 @@ impl Spanned for Statement {
Statement::DropExtension(drop_extension) => drop_extension.span(),
Statement::DropOperator(drop_operator) => drop_operator.span(),
Statement::DropOperatorFamily(drop_operator_family) => drop_operator_family.span(),
Statement::DropOperatorClass(drop_operator_class) => drop_operator_class.span(),
Statement::CreateSecret { .. } => Span::empty(),
Statement::CreateServer { .. } => Span::empty(),
Statement::CreateConnector { .. } => Span::empty(),

View file

@ -6773,9 +6773,11 @@ impl<'a> Parser<'a> {
} else if self.parse_keyword(Keyword::EXTENSION) {
return self.parse_drop_extension();
} else if self.parse_keyword(Keyword::OPERATOR) {
// Check if this is DROP OPERATOR FAMILY
// Check if this is DROP OPERATOR FAMILY or DROP OPERATOR CLASS
return if self.parse_keyword(Keyword::FAMILY) {
self.parse_drop_operator_family()
} else if self.parse_keyword(Keyword::CLASS) {
self.parse_drop_operator_class()
} else {
self.parse_drop_operator()
};
@ -7594,6 +7596,23 @@ impl<'a> Parser<'a> {
}))
}
/// Parse a [Statement::DropOperatorClass]
///
/// [PostgreSQL Documentation](https://www.postgresql.org/docs/current/sql-dropopclass.html)
pub fn parse_drop_operator_class(&mut self) -> Result<Statement, ParserError> {
let if_exists = self.parse_keywords(&[Keyword::IF, Keyword::EXISTS]);
let names = self.parse_comma_separated(|p| p.parse_object_name(false))?;
self.expect_keyword(Keyword::USING)?;
let using = self.parse_identifier()?;
let drop_behavior = self.parse_optional_drop_behavior();
Ok(Statement::DropOperatorClass(DropOperatorClass {
if_exists,
names,
using,
drop_behavior,
}))
}
//TODO: Implement parsing for Skewed
pub fn parse_hive_distribution(&mut self) -> Result<HiveDistributionStyle, ParserError> {
if self.parse_keywords(&[Keyword::PARTITIONED, Keyword::BY]) {