PostgresOSM.database_exists

PostgresOSM.database_exists(database_name=None)

Check if a database exists in the PostgreSQL server being connected.

Parameters

database_name (str or None) – name of a database, defaults to None

Returns

True if the database exists, False, otherwise

Return type

bool

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.

>>> testdb.database_exists('testdb')
True

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

>>> testdb.database_exists('testdb')
False