'Create a Database with name from variable on Databricks (in SQL, not in Spark)
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 :
Solution 1:[1]
You can accomplish this by string interpolating using widgets:
CREATE DATABASE IF NOT EXISTS ${env}_BackOffice
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Alex Python |