PostgreSQL.get_schema_names(include_all=False, names_only=True, verbose=False)

Get the names of existing schemas.

  • include_all (bool) – whether to list all the available schemas, defaults to False

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

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


schema names

Return type

list or pandas.DataFrame or None


>>> from pyhelpers.dbms import PostgreSQL

>>> testdb = PostgreSQL('localhost', 5432, 'postgres', database_name='testdb')
Password (postgres@localhost:5432): ***
Creating a database: "testdb" ... Done.
Connecting postgres:***@localhost:5432/testdb ... Successfully.

>>> testdb.get_schema_names()

>>> testdb.get_schema_names(include_all=True, names_only=False)
          schema_name  schema_id      role
0  information_schema      13388  postgres
1          pg_catalog         11  postgres
2            pg_toast         99  postgres
3              public       2200  postgres

>>> testdb.drop_schema(schema_names='public', verbose=True)
To drop the schema "public" from postgres:***@localhost:5432/testdb
? [No]|Yes: yes
Dropping "public" ... Done.

>>> testdb.get_schema_names()  # None

>>> testdb.get_schema_names(verbose=True)
No schema exists in the currently-connected database "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.