PostgreSQL.drop_database¶
- PostgreSQL.drop_database(database_name=None, confirmation_required=True, verbose=False)[source]¶
Delete/drop a database.
- Parameters:
database_name (str | None) – Name of the database to be dropped. If
database_name=None
(default), drop the currently connected database.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): *** Connecting postgres:***@localhost:5432/testdb ... Successfully. >>> testdb.database_name 'testdb' >>> testdb.drop_database(verbose=True) # Delete the database "testdb" To drop the database "testdb" from postgres:***@localhost:5432 ? [No]|Yes: yes Dropping "testdb" ... Done. >>> testdb.database_exists(database_name='testdb') False >>> testdb.drop_database(database_name='testdb', verbose=True) The database "testdb" does not exist. >>> testdb.database_name 'postgres'