- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2024 08:43 AM - edited 12-11-2024 08:47 AM
I'm struggeling using the databricks widget to set up the location in an sql create table statement.
I tried the following to set up the location:
Step1: Creating a notebook (Notebook1) to define the variable.
Location_Path = 'abfss:xxxxx@xxxx.xxx.net/Tabelname1'
Step2: Creating a notebook with widgets (Notebook2) to create the table.
Cell2:
%sql
-- create table using widget
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2024 02:08 AM
I finaly solved my problem by using the parameters in python F-Strings:
Location_Path = dbutils.widgets.text("Location_Path","")
-- create table using widget
query = f"""
CREATE OR REPLACE TABLE schema.Tabelname1
LOCATION '{Location_Path}'
AS
SELECT
...
from schema.Tabelname
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2024 09:12 AM
Hi @Timmes0815 - could you please try the below example and let us know?
Location_Path = dbutils.widgets.text("Location_Path","")
Location_Path = dbutils.widgets.getArgument("Location_Path")
display(Location_Path)
dbutils.notebook.run("Notebook2", 600, {"Location_Path":Location_Path})
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2024 04:21 AM - edited 12-12-2024 04:27 AM
@shan_chandra thainks for your reply. I tried it today but it didn't work. The result from display(Location_Path) is exactly the name of the location. The location is something like
'abfss://abcd@xxxxx.dfs.core.windows.net/mytable'
Puting the location into the SQL works using the :Location_Path Parameter fails. Strange is, that I've additional parameters in my SQL like "Start_Date" and "End_Date" which works fine. Only the parameter for the location is not working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2024 02:08 AM
I finaly solved my problem by using the parameters in python F-Strings:
Location_Path = dbutils.widgets.text("Location_Path","")
-- create table using widget
query = f"""
CREATE OR REPLACE TABLE schema.Tabelname1
LOCATION '{Location_Path}'
AS
SELECT
...
from schema.Tabelname
![](/skins/images/B38AF44D4BD6CE643D2A527BE673CCF6/responsive_peak/images/icon_anonymous_message.png)
![](/skins/images/B38AF44D4BD6CE643D2A527BE673CCF6/responsive_peak/images/icon_anonymous_message.png)