PostgreSQL.get_schema_names
- PostgreSQL.get_schema_names(include_all=False, names_only=True, column_names=None, verbose=False)[source]
Get the names of existing schemas.
- Parameters:
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
column_names (None or list) – column names of the returned dataframe if
names_only=False
; whencolumn_names=None
, it defaults to['schema_name', 'schema_id', 'role']
verbose (bool or int) – whether to print relevant information in console, defaults to
False
- Returns:
schema names
- Return type:
list or pandas.DataFrame or None
Examples:
>>> 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() ['public'] >>> testdb.get_schema_names(include_all=True, names_only=False) schema_name schema_owner oid nspowner 0 public pg_database_owner 2200 6171 1 pg_toast postgres 99 10 2 pg_catalog postgres 11 10 3 information_schema postgres 13183 10 >>> 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.