sabir-akhadov-localstack commented on code in PR #2730:
URL:
https://github.com/apache/datafusion-sqlparser-rs/pull/2730#discussion_r4391534960
##########
tests/sqlparser_postgres.rs:
##########
@@ -11014,3 +11014,102 @@ fn
parse_alter_operator_family_order_by_followed_by_search() {
]
);
}
+
+#[test]
+fn parse_alter_view_postgres() {
Review Comment:
`parse_alter_view` has no dialect check, so these could use `all_dialects()`
next to the existing `parse_alter_view` tests in `sqlparser_common.rs`.
##########
src/ast/ddl.rs:
##########
@@ -4806,6 +4806,142 @@ impl Spanned for AlterCollation {
}
}
+/// `ALTER VIEW` statement.
+#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
+#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
+#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
+pub struct AlterView {
+ /// View name being altered.
+ #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
+ pub name: ObjectName,
+ /// Whether `IF EXISTS` was specified.
+ pub if_exists: bool,
+ /// The operation to perform on the view.
+ pub operation: AlterViewOperation,
+}
+
+/// Operations supported by `ALTER VIEW`.
+///
+/// See
[PostgreSQL](https://www.postgresql.org/docs/current/sql-alterview.html)
+#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
+#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
+#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
+pub enum AlterViewOperation {
+ /// Replace the view definition.
+ ///
+ /// ```sql
+ /// ALTER VIEW name [ (columns) ] [ WITH (options) ] AS query
+ /// ```
+ ///
+ /// See [MySQL](https://dev.mysql.com/doc/refman/8.4/en/alter-view.html)
+ As {
+ /// Optional new column list for the view.
+ columns: Vec<Ident>,
+ /// Replacement query for the view definition.
+ query: Box<Query>,
+ /// Additional `WITH` options for the view.
+ with_options: Vec<SqlOption>,
+ },
+ /// ```sql
+ /// ALTER VIEW name ALTER [ COLUMN ] column_name { SET DEFAULT expression
| DROP DEFAULT }
+ /// ```
+ AlterColumn {
+ /// The column to alter.
+ column_name: Ident,
+ /// Either [`AlterColumnOperation::SetDefault`] or
[`AlterColumnOperation::DropDefault`].
+ op: AlterColumnOperation,
+ },
+ /// ```sql
+ /// ALTER VIEW name OWNER TO { new_owner | CURRENT_ROLE | CURRENT_USER |
SESSION_USER }
+ /// ```
+ OwnerTo(Owner),
+ /// ```sql
+ /// ALTER VIEW name RENAME [ COLUMN ] column_name TO new_column_name
+ /// ```
+ RenameColumn {
+ /// Existing column name.
+ old_column_name: Ident,
+ /// New column name.
+ new_column_name: Ident,
+ },
+ /// ```sql
+ /// ALTER VIEW name RENAME TO new_name
+ /// ```
+ RenameTo {
+ /// New view name.
+ new_name: ObjectName,
+ },
+ /// ```sql
+ /// ALTER VIEW name SET SCHEMA new_schema
+ /// ```
+ SetSchema {
+ /// Target schema name.
+ schema_name: ObjectName,
+ },
+ /// ```sql
+ /// ALTER VIEW name SET ( view_option_name [ = view_option_value ] [, ...
] )
+ /// ```
+ SetOptions {
+ /// Options to set, [`SqlOption::Ident`] when no value is given.
+ options: Vec<SqlOption>,
+ },
+ /// ```sql
+ /// ALTER VIEW name RESET ( view_option_name [, ... ] )
+ /// ```
+ ResetOptions {
+ /// Options to reset.
+ options: Vec<Ident>,
+ },
+}
+
+impl fmt::Display for AlterViewOperation {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ match self {
+ AlterViewOperation::As {
+ columns,
+ query,
+ with_options,
+ } => {
+ if !with_options.is_empty() {
+ write!(f, "WITH ({}) ",
display_comma_separated(with_options))?;
Review Comment:
Pre-existing, but the parser reads `(columns)` before `WITH (...)` while
this writes them the other way round, so `ALTER VIEW v (a) WITH (x = 1) AS
SELECT 1` displays as `ALTER VIEW v WITH (x = 1) (a) AS SELECT 1`, which
doesn't re-parse. Swapping the two blocks here fixes the round-trip.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]