Legacy notebook widgets: ${param}
The ${param}
syntax for accessing widget values has been deprecated in Databricks Runtime 15.2 and above. Use the current Databricks widgets syntax, (:param
) instead.
This page shows you how to use the legacy ${param}
syntax for notebooks widgets running on Databricks Runtime 15.1 and below. Databricks recommends you migrate to the current syntax.
Use widget values in Databricks Runtime 15.1 and below
This section describes how to pass Databricks widgets values to %sql
notebook cells in Databricks Runtime 15.1 and below.
- Create widgets to specify text values.
- Python
- Scala
- R
- SQL
dbutils.widgets.text("database", "")
dbutils.widgets.text("table", "")
dbutils.widgets.text("filter_value", "100")
dbutils.widgets.text("database", "")
dbutils.widgets.text("table", "")
dbutils.widgets.text("filter_value", "100")
dbutils.widgets.text("database", "")
dbutils.widgets.text("table", "")
dbutils.widgets.text("filter_value", "100")
CREATE WIDGET TEXT database DEFAULT ""
CREATE WIDGET TEXT table DEFAULT ""
CREATE WIDGET TEXT filter_value DEFAULT "100"
-
Pass in the widget values using the
${param}
syntax.SQLSELECT *
FROM ${database}.${table}
WHERE col == ${filter_value}
LIMIT 100
To escape the $
character in a SQL string literal, use \$
. For example, to express the string $1,000
, use "\$1,000"
. The $
character cannot be escaped for SQL identifiers.
Migrate to parameter markers
The following table shows common use cases for parameters, the original Databricks widget syntax (deprecated in Databricks Runtime 15.2 and above), and the equivalent syntax using named parameter marker syntax (supported in Databricks Runtime 15.2 and above).
Parameter use case |
|
|
---|---|---|
Load only data before a specified date |
You must include quotes around the date parameter and curly brackets. |
|
Load only data less than a specified numeric value |
|
|
Compare two strings |
|
|
Specify the table used in a query |
|
When a user enters this parameter, they should use the full three-level namespace to identify the table. |
Independently specify the catalog, schema, and table used in a query |
|
|
Use parameters as a template in a longer, formatted string |
Parameter values are automatically concatenated as a string. |
See Concatenate multiple parameters for a complete example. |
Create an interval |
|
|
Filter by a list of possible values |
|
|