PostgreSQL.get_database_names

PostgreSQL.get_database_names(names_only=True)

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.

>>> postgres.get_database_names()
['template1',
 'template0',
 'postgis_32_sample',
 'postgres']