-
Notifications
You must be signed in to change notification settings - Fork 553
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds support for pg DROP EXTENSION #1610
base: main
Are you sure you want to change the base?
Conversation
``` DROP EXTENSION [ IF EXISTS ] name [, ...] [ CASCADE | RESTRICT ] ``` https://www.postgresql.org/docs/current/sql-dropextension.html
Our migration tests have used strings in Rust files (for exo and expected SQL), which required string escaping, prefix stripping, and other modifications. This made it difficult to read and extend the test code (for example, consider `MigrationScope`s). Also, we relied on exact string matches, which required paying too much attention to the precise format. This refactoring: 1. Move .exo and .sql files outside of rust code 2. Use `sqlparser` to match without considering the format Note that in some cases, `sqlparser` doesn't parse valid syntax, so we rely on exact string comparison as a fallback/optimization. We have already contributed a couple of changes (apache/datafusion-sqlparser-rs#1608, apache/datafusion-sqlparser-rs#1610) and will continue to do so to remove this reliance.
@@ -2759,6 +2759,15 @@ pub enum Statement { | |||
version: Option<Ident>, | |||
}, | |||
/// ```sql | |||
/// DROP EXTENSION [ IF EXISTS ] name [, ...] [ CASCADE | RESTRICT ] | |||
/// ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we also include the link in the description here? would help folks find the syntax quicker in the future if needed
@@ -5861,6 +5863,22 @@ impl<'a> Parser<'a> { | |||
}) | |||
} | |||
|
|||
pub fn parse_drop_extension(&mut self) -> Result<Statement, ParserError> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the function is being made a public function, could we include a description for it?
cascade_or_restrict: cascade_or_restrict.map(|k| match k { | ||
Keyword::CASCADE => ReferentialAction::Cascade, | ||
Keyword::RESTRICT => ReferentialAction::Restrict, | ||
_ => unreachable!(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in place of panicking here in case we missed something/bug, we can return an explicit error return self.expected(..)
?
@@ -662,6 +662,22 @@ fn parse_create_extension() { | |||
.verified_stmt("CREATE EXTENSION extension_name WITH SCHEMA schema_name VERSION version"); | |||
} | |||
|
|||
#[test] | |||
fn parse_drop_extension() { | |||
pg_and_generic().verified_stmt("DROP EXTENSION extension_name"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the feature introduces a new node to the ast can we add one scenario that asserts the ast in this style?
https://www.postgresql.org/docs/current/sql-dropextension.html