Venkatesh
Venkatesh

Reputation: 107

How to Create the database from the variable in the pyspark in pyspark?

1.How to create the database using varible in pyspark.Assume we have variable with database name .using that variable how to create the database in the pyspark.

Var a="databasename"

create database a

can you please it is possible to use the variable?

Upvotes: 1

Views: 3616

Answers (1)

Alex Ott
Alex Ott

Reputation: 87204

Just use spark.sql to execute corresponding CREATE DATABASE command:

db_name = "some_name"
spark.sql(f"CREATE DATABASE IF NOT EXISTS {db_name}")

Upvotes: 2

Related Questions