pyspark.sql.Catalog.databaseExists

Catalog.databaseExists(dbName: str) → bool

Check if the database with the specified name exists.

Parameters
dbNamestr

name of the database to check existence

Returns
bool

Indicating whether the database exists

Allowed dbName to be qualified with catalog name.

Examples

>>> spark.catalog.databaseExists("test_new_database")
False
>>> df = spark.sql("CREATE DATABASE test_new_database")
>>> spark.catalog.databaseExists("test_new_database")
True
>>> spark.catalog.databaseExists("spark_catalog.test_new_database")
True
>>> df = spark.sql("DROP DATABASE test_new_database")