Reputation: 143
How to create a database with a name from a variable (in SQL, not in Spark) ?
I've written this :
%sql
SET myVar = CONCAT(getArgument('env'), 'BackOffice');
CREATE DATABASE IF NOT EXISTS myVar
("env" is a dropdown widgets)
But it creates me a database called "myvar".
EDIT 1 :
When I use ${myVar}, it shows me this :
And this :
Here is the link of "current SQL widgets" : https://docs.databricks.com/notebooks/widgets.html#widgets-in-sql
EDIT 2 :
When I type this, it works :
But not this :
Upvotes: 1
Views: 1983
Reputation: 78
You can accomplish this by string interpolating using widgets:
CREATE DATABASE IF NOT EXISTS ${env}_BackOffice
Upvotes: 1