pyspark.sql.Catalog.databaseExists#
- Catalog.databaseExists(dbName)[source]#
Check if the database with the specified name exists.
New in version 3.3.0.
- Parameters
- dbNamestr
name of the database to check existence
Changed in version 3.4.0: Allow
dbName
to be qualified with catalog name.
- Returns
- bool
Indicating whether the database exists
Examples
Check if ‘test_new_database’ database exists
>>> spark.catalog.databaseExists("test_new_database") False >>> _ = spark.sql("CREATE DATABASE test_new_database") >>> spark.catalog.databaseExists("test_new_database") True
Using the fully qualified name with the catalog name.
>>> spark.catalog.databaseExists("spark_catalog.test_new_database") True >>> _ = spark.sql("DROP DATABASE test_new_database")