Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a placeholder in table name in databricks

Tags:

sql

databricks

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}
like image 929
user19930511 Avatar asked Nov 16 '25 09:11

user19930511


1 Answers

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

like image 188
Dipanjan Mallick Avatar answered Nov 19 '25 10:11

Dipanjan Mallick