Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2025 07:24 AM
Try this
The SQL script snippet provided (
DECLARE OR REPLACE var query = "SELECT :PARAMETER_1"; EXECUTE IMMEDIATE query;) will not work as intended in Databricks SQL because it uses a placeholder :PARAMETER_1 without properly assigning a value to it or using a parameterized query format compatible with Databricks SQL.The error most likely corresponds to unbound SQL parameters, meaning the declared parameter (
:PARAMETER_1) is not bound to a concrete value at execution time. Also, Databricks SQL doesn't support bound parameter syntax like PostgreSQL or Oracle.To address this issue, you should:
- Directly substitute the desired value into the query string rather than using unbound parameters.
- Avoid usage of
EXECUTE IMMEDIATEunless required in a procedural-like SQL flow. Typically, you would write queries in standard SQL directly.
Here is a working structure for SQL in Databricks for a valid query:
DECLARE my_param STRING;
SET my_param = 'desired_value';
SELECT ${my_param};
This approach ensures that the value is dynamically assigned and incorporated into the SQL query.
The error documentation from Azure Databricks confirms the need for properly binding or removing unbound parameters in SQL queries.
Cheers, Louis.