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 src/ast/ddl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4386,6 +4386,7 @@ pub struct CreateView {
/// <https://docs.snowflake.com/en/sql-reference/sql/create-view#syntax>
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:
Expand Down
21 changes: 21 additions & 0 deletions src/ast/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
}

impl Visitor for RelationVisitor {
type Break = ();

fn pre_visit_relation(&mut self, relation: &ObjectName) -> ControlFlow<Self::Break> {
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)]
Expand Down
Loading