PostgreSQL.get_database_names

PostgreSQL.get_database_names(names_only=True)[source]

Get names of all existing databases.

Parameters:

names_only (bool) – whether to return only the names of the databases, defaults to True

Returns:

names of all existing databases

Return type:

list or pandas.DataFrame

Examples:

>>> from pyhelpers.dbms import PostgreSQL

>>> # Connect the default database 'postgres'
>>> # postgres = PostgreSQL('localhost', 5432, 'postgres', database_name='postgres')
>>> postgres = PostgreSQL()
Password (postgres@localhost:5432): ***
Connecting postgres:***@localhost:5432/postgres ... Successfully.

>>> isinstance(postgres.get_database_names(), list)
True
>>> 'postgres' in postgres.get_database_names()
True