PostgreSQL.drop_schema¶
- PostgreSQL.drop_schema(schema_names, confirmation_required=True, verbose=False)[source]¶
Delete/drop one or multiple schemas.
- Parameters:
schema_names (str | Iterable[str]) – Name of one schema or names of multiple schemas to be dropped.
confirmation_required (bool) – Whether to prompt for confirmation before proceeding; defaults to
True
.verbose (bool | int) – Whether to print relevant information to the console; defaults to
False
.
Examples:
>>> from pyhelpers.dbms import PostgreSQL >>> testdb = PostgreSQL(database_name='testdb', verbose=True) Password (postgres@localhost:5432): *** Creating a database: "testdb" ... Done. Connecting postgres:***@localhost:5432/testdb ... Successfully. >>> new_schema_names = ['points', 'lines', 'polygons'] >>> for new_schema in new_schema_names: ... testdb.create_schema(new_schema, verbose=True) Creating a schema: "points" ... Done. Creating a schema: "lines" ... Done. Creating a schema: "polygons" ... Done. >>> new_schema_names_ = ['test_schema'] >>> testdb.drop_schema(new_schema_names + new_schema_names_, verbose=True) To drop the following schemas from postgres:***@localhost:5432/testdb: "points" "lines" "polygons" "test_schema" ? [No]|Yes: yes Dropping ... "points" ... Done. "lines" ... Done. "polygons" ... Done. "test_schema" (does not exist.) >>> testdb.drop_database(verbose=True) # Delete the database "testdb" To drop the database "testdb" from postgres:***@localhost:5432 ? [No]|Yes: yes Dropping "testdb" ... Done.