0
0

More than 1 year has passed since last update.

Databricks ( Spark ) にて前方一致したデータベース(スキーマ)を削除する方法

Posted at

概要

Databricks ( Spark ) にて前方一致したデータベース(スキーマ)を削除する方法を共有します。

実践例

1. 削除対象のデータベースを作成

%sql
create database _test_1;
create database _test_2;
create database _test_3;
create database _test_4;

image.png

1. 前方一致したデータベース(例:_testではじまるデータベース)を DROP

db_prefix = '_test'
 
dbs = spark.sql(f"SHOW DATABASES '{db_prefix}*'").select('databaseName').collect()
for db_index in range(len(dbs)):
    db_name = dbs[db_index][0]
    spark.sql(f'DROP DATABASE {db_name} CASCADE')
    print(f'{db_name} is dropped.')

image.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0