Skip to content

Commit

Permalink
fix: include schema for view name in rw_relations show create view (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
hzxa21 authored Oct 30, 2024
1 parent 68b470e commit c706e8d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fn read_rw_view_info(reader: &SysCatalogReaderImpl) -> Result<Vec<RwView>> {
name: view.name().to_string(),
schema_id: schema.id() as i32,
owner: view.owner as i32,
definition: view.create_sql(),
definition: view.create_sql(schema.name()),
acl: get_acl_items(&Object::ViewId(view.id), false, &users, username_map),
})
})
Expand Down
8 changes: 6 additions & 2 deletions src/frontend/src/catalog/view_catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,12 @@ impl ViewCatalog {
}

/// Returns the SQL statement that can be used to create this view.
pub fn create_sql(&self) -> String {
format!("CREATE VIEW {} AS {}", self.name, self.sql)
pub fn create_sql(&self, schema: String) -> String {
if schema == "public" {
format!("CREATE VIEW {} AS {}", self.name, self.sql)
} else {
format!("CREATE VIEW {}.{} AS {}", schema, self.name, self.sql)
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/handler/show.rs
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ pub fn handle_show_create_object(
let view = schema
.get_view_by_name(&object_name)
.ok_or_else(|| CatalogError::NotFound("view", name.to_string()))?;
view.create_sql()
view.create_sql(schema.name())
}
ShowCreateType::Table => {
let table = schema
Expand Down

0 comments on commit c706e8d

Please sign in to comment.