#include "nodes/makefuncs.h"
#include "parser/parse_type.h"
#include "utils/builtins.h"
+#include "utils/lsyscache.h"
#include "utils/syscache.h"
ReleaseSysCache(tup);
}
+ /*
+ * Prevent the drop of a temporary schema, be it owned by the current
+ * session or another backend as this would mess up with the callback
+ * registered to clean up temporary objects at the end of a session.
+ * Note also that the creation of any follow-up temporary object would
+ * result in inconsistencies within the session whose temporary schema
+ * has been dropped.
+ */
+ if (stmt->removeType == OBJECT_SCHEMA &&
+ isAnyTempNamespace(address.objectId))
+ ereport(ERROR,
+ (errcode(ERRCODE_WRONG_OBJECT_TYPE),
+ errmsg("cannot drop temporary schema \"%s\"",
+ get_namespace_name(address.objectId))));
+
/* Check permissions. */
namespaceId = get_object_namespace(&address);
if (!OidIsValid(namespaceId) ||