databaseExists

检查具有指定名称的数据库是否存在。

Syntax

databaseExists(dbName: str)

参数

参数 类型 Description
dbName str 要检查是否存在的数据库的名称。 可以使用目录名称进行限定。

退货

bool

指示数据库是否存在。

示例

# 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")