risingwave_frontend/handler/
drop_connection.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_connection(
25 handler_args: HandlerArgs,
26 connection_name: ObjectName,
27 if_exists: bool,
28) -> Result<RwPgResponse> {
29 let session = handler_args.session;
30 let db_name = &session.database();
31 let (schema_name, connection_name) =
32 Binder::resolve_schema_qualified_name(db_name, connection_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 connection_id = {
39 let reader = session.env().catalog_reader().read_guard();
40 let (connection, schema_name) =
41 match reader.get_connection_by_name(db_name, schema_path, connection_name.as_str()) {
42 Ok((c, s)) => (c, s),
43 Err(e) => {
44 return if if_exists {
45 Ok(RwPgResponse::builder(StatementType::DROP_CONNECTION)
46 .notice(format!(
47 "connection \"{}\" does not exist, skipping",
48 connection_name
49 ))
50 .into())
51 } else {
52 Err(e.into())
53 };
54 }
55 };
56 session.check_privilege_for_drop_alter(schema_name, &**connection)?;
57
58 connection.id
59 };
60
61 let catalog_writer = session.catalog_writer()?;
62 catalog_writer.drop_connection(connection_id).await?;
63
64 Ok(PgResponse::empty_result(StatementType::DROP_CONNECTION))
65}