DROP_SCHEMA(7pg15)

πŸ“¦ version 15.19, in opensuse-leap 16.0

πŸ’… DROP_SCHEMA πŸ’…

Okay bestie, this is the DROP SCHEMA(7) page from the PostgreSQL 15.19 docs, and it’s all about yeeting schemas out of your database. Let’s get into it ✨


🌸 NAME 🌸

DROP_SCHEMA β€” remove a schema


πŸŽ€ SYNOPSIS πŸŽ€

DROP SCHEMA [ IF EXISTS ] name [, ...] [ CASCADE | RESTRICT ]

πŸ¦‹ DESCRIPTION πŸ¦‹

DROP SCHEMA removes schemas from the database. Slay, but carefully πŸ’…

A schema can only be dropped by its owner or a superuser. And just so you know: the owner can drop the schema (and thereby all contained objects) even if they do not own some of the objects within the schema. That’s the rule, no cap.


✨ PARAMETERS ✨

  • IF EXISTS β€” Do not throw an error if the schema does not exist. A notice is issued in this case. So it’s like, β€œbestie, it’s not here, but we move” instead of a full error moment.
  • name β€” The name of a schema. Literally the schema’s name, periodt.
  • CASCADE β€” Automatically drop objects (tables, functions, etc.) that are contained in the schema, and in turn all objects that depend on those objects (see Section 5.14). This is the β€œtake everything with it” option πŸ”₯
  • RESTRICT β€” Refuse to drop the schema if it contains any objects. This is the default. Very β€œnope, not unless it’s empty” energy.

πŸ’€ NOTES πŸ’€

Using the CASCADE option might make the command remove objects in other schemas besides the one(s) named. So yeah, CASCADE can reach outside the group chat β€” be aware, bestie 😭

πŸ“ EXAMPLES πŸ“

To remove schema mystuff from the database, along with everything it contains:

DROP SCHEMA mystuff CASCADE;

🌈 COMPATIBILITY 🌈

DROP SCHEMA is fully conforming with the SQL standard, except that the standard only allows one schema to be dropped per command, and apart from the IF EXISTS option, which is a PostgreSQL extension. Standard-ish, but make it PostgreSQL πŸ’–


πŸ‘‘ SEE ALSO πŸ‘‘


PostgreSQL 15.19 β€’ 2026 β€’ DROP SCHEMA(7) β€” mwah, that’s the page, bestie πŸ«ΆπŸ’–βœ¨

πŸ“¦ where this page comes from