PostgresOSM.drop_schema

PostgresOSM.drop_schema(schema_names, confirmation_required=True, verbose=False)

Drop a schema in the database being connected.

Parameters
  • schema_names (str or typing.Iterable) – name of one schema, or names of multiple schemas

  • confirmation_required (bool) – whether to prompt a message for confirmation to proceed, defaults to True

  • verbose (bool or int) – whether to print relevant information in console as the function runs, defaults to False

Example:

>>> from pyhelpers.sql import PostgreSQL

>>> testdb = PostgreSQL('localhost', 5432, username='postgres', database_name='testdb')
Password (postgres@localhost:5432): ***
Connecting postgres:***@localhost:5432/testdb ... Successfully.

>>> new_schema_names = ['points', 'lines', 'polygons']
>>> new_schema_names_ = ['test_schema']

>>> 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.

>>> 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.)

>>> # Delete the database "testdb"
>>> testdb.drop_database(verbose=True)
To drop the database "testdb" from postgres:***@localhost:5432
? [No]|Yes: yes
Dropping "testdb" ... Done.