Home > OS >  How to create a placeholder in table name in databricks
How to create a placeholder in table name in databricks

Time:03-07

Hope the title clarifies what I actually want. I will try to describe the problem.

I am looking for something like this :

variable = "1"
%sql 
DROP TABLE IF EXISTS database.table_{variable}

CodePudding user response:

If you use Spark SQL within Python notebook you can easily achieve this with strings as below -

%python

spark.sql("DROP TABLE IF EXISTS database.table_{variable}".format(variable=variable))

Alternatively, you can follow the link below achieving the same using SQL as well -

Assign a variable a dynamic value in SQL in Databricks / Spark

  • Related