risingwave_frontend/handler/
drop_view.rs1use pgwire::pg_response::{PgResponse, StatementType};
16use risingwave_sqlparser::ast::ObjectName;
17
18use super::RwPgResponse;
19use crate::binder::Binder;
20use crate::catalog::root_catalog::SchemaPath;
21use crate::error::Result;
22use crate::handler::HandlerArgs;
23
24pub async fn handle_drop_view(
25 handler_args: HandlerArgs,
26 table_name: ObjectName,
27 if_exists: bool,
28 cascade: bool,
29) -> Result<RwPgResponse> {
30 let session = handler_args.session;
31 let db_name = &session.database();
32 let (schema_name, table_name) = Binder::resolve_schema_qualified_name(db_name, table_name)?;
33 let search_path = session.config().search_path();
34 let user_name = &session.user_name();
35
36 let schema_path = SchemaPath::new(schema_name.as_deref(), &search_path, user_name);
37
38 let view_id = {
39 let reader = session.env().catalog_reader().read_guard();
40 let (view, schema_name) =
41 match reader.get_view_by_name(&session.database(), schema_path, &table_name) {
42 Ok((t, s)) => (t, s),
43 Err(e) => {
44 return if if_exists {
45 Ok(RwPgResponse::builder(StatementType::DROP_VIEW)
46 .notice(format!("view \"{}\" does not exist, skipping", table_name))
47 .into())
48 } else {
49 Err(e.into())
50 };
51 }
52 };
53
54 session.check_privilege_for_drop_alter(schema_name, &**view)?;
55
56 view.id
57 };
58
59 let catalog_writer = session.catalog_writer()?;
60 catalog_writer.drop_view(view_id, cascade).await?;
61
62 Ok(PgResponse::empty_result(StatementType::DROP_VIEW))
63}