diff --git a/src/ast/ddl.rs b/src/ast/ddl.rs index a0e69ad8a..5146454d4 100644 --- a/src/ast/ddl.rs +++ b/src/ast/ddl.rs @@ -4386,6 +4386,7 @@ pub struct CreateView { /// pub secure: bool, /// View name + #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))] pub name: ObjectName, /// If `if_not_exists` is true, this flag is set to true if the view name comes before the `IF NOT EXISTS` clause. /// Example: diff --git a/src/ast/visitor.rs b/src/ast/visitor.rs index 9011a94d5..41b703207 100644 --- a/src/ast/visitor.rs +++ b/src/ast/visitor.rs @@ -1242,6 +1242,27 @@ mod tests { do_visit("SELECT a, b FROM t", &mut visitor); assert_eq!(visitor.idents, vec!["a", "b", "t"]); } + + #[derive(Default)] + struct RelationVisitor { + relations: Vec, + } + + impl Visitor for RelationVisitor { + type Break = (); + + fn pre_visit_relation(&mut self, relation: &ObjectName) -> ControlFlow { + self.relations.push(relation.to_string()); + ControlFlow::Continue(()) + } + } + + #[test] + fn test_visit_create_view_name_as_relation() { + let mut visitor = RelationVisitor::default(); + do_visit("CREATE VIEW db1.v AS SELECT * FROM t", &mut visitor); + assert_eq!(visitor.relations, vec!["db1.v", "t"]); + } } #[cfg(test)]