@@ -957,61 +957,42 @@ $$ LANGUAGE plpgsql RETURNS NULL ON NULL INPUT;
957
957
-- --------------------------------------------------------------------------------------------------
958
958
959
959
960
- -- Drop schema -------------------------------------------------------------------------------------
961
-
962
960
CREATE OR REPLACE FUNCTION
963
- __msar .drop_schema (sch_name text , cascade_ boolean , if_exists boolean ) RETURNS TEXT AS $$/*
964
- Drop a schema, returning the command executed.
961
+ msar .drop_schema (sch_name text , cascade_ boolean ) RETURNS void AS $$/*
962
+ Drop a schema
963
+
964
+ If no schema exists with the given name, an exception will be raised.
965
965
966
966
Args:
967
- sch_name: A properly quoted name of the schema to be dropped
968
- cascade_: Whether to drop dependent objects.
969
- if_exists: Whether to ignore an error if the schema doesn't exist
967
+ sch_name: An unqoted name of the schema to be dropped
968
+ cascade_: When true, dependent objects will be dropped automatically
970
969
*/
971
970
DECLARE
972
- cmd_template text ;
971
+ cascade_sql text = CASE cascade_ WHEN TRUE THEN ' CASCADE ' ELSE ' ' END ;
973
972
BEGIN
974
- IF if_exists
975
- THEN
976
- cmd_template := ' DROP SCHEMA IF EXISTS %s' ;
977
- ELSE
978
- cmd_template := ' DROP SCHEMA %s' ;
979
- END IF;
980
- IF cascade_
981
- THEN
982
- cmd_template = cmd_template || ' CASCADE' ;
983
- END IF;
984
- RETURN __msar .exec_ddl (cmd_template, sch_name);
973
+ EXECUTE ' DROP SCHEMA ' || quote_ident(sch_name) || cascade_sql;
985
974
END;
986
975
$$ LANGUAGE plpgsql RETURNS NULL ON NULL INPUT;
987
976
988
977
989
978
CREATE OR REPLACE FUNCTION
990
- msar .drop_schema (sch_id oid , cascade_ boolean , if_exists boolean ) RETURNS TEXT AS $$/*
991
- Drop a schema, returning the command executed.
992
-
993
- Args:
994
- sch_id: The OID of the schema to drop
995
- cascade_: Whether to drop dependent objects.
996
- if_exists: Whether to ignore an error if the schema doesn't exist
997
- */
998
- BEGIN
999
- RETURN __msar .drop_schema (__msar .get_schema_name (sch_id), cascade_, if_exists);
1000
- END;
1001
- $$ LANGUAGE plpgsql RETURNS NULL ON NULL INPUT;
979
+ msar .drop_schema (sch_id oid , cascade_ boolean ) RETURNS void AS $$/*
980
+ Drop a schema
1002
981
1003
-
1004
- CREATE OR REPLACE FUNCTION
1005
- msar .drop_schema (sch_name text , cascade_ boolean , if_exists boolean ) RETURNS TEXT AS $$/*
1006
- Drop a schema, returning the command executed.
982
+ If no schema exists with the given oid, an exception will be raised.
1007
983
1008
984
Args:
1009
- sch_name: An unqoted name of the schema to be dropped
1010
- cascade_: Whether to drop dependent objects.
1011
- if_exists: Whether to ignore an error if the schema doesn't exist
985
+ sch_id: The OID of the schema to drop
986
+ cascade_: When true, dependent objects will be dropped automatically
1012
987
*/
988
+ DECLARE
989
+ sch_name text ;
1013
990
BEGIN
1014
- RETURN __msar .drop_schema (quote_ident(sch_name), cascade_, if_exists);
991
+ SELECT nspname INTO sch_name FROM pg_namespace WHERE oid = sch_id;
992
+ IF sch_name IS NULL THEN
993
+ RAISE EXCEPTION ' No schema with OID % exists.' , sch_id;
994
+ END IF;
995
+ PERFORM msar .drop_schema (sch_name, cascade_);
1015
996
END;
1016
997
$$ LANGUAGE plpgsql RETURNS NULL ON NULL INPUT;
1017
998
0 commit comments