kamal_ch
Databricks Employee
Databricks Employee

Hi @dileepkumar_t 

The UNBOUND_SQL_PARAMETER error in Databricks SQL Agent occurs when a parameter marker in a SQL query is not associated with a value. This error is raised because the SQL query is expecting a parameter to be provided, but it has not been properly bound to a value.To resolve this error for the query SELECT nation.n_nationkey, nation.n_name, nation.n_regionkey, nation.n_comment FROM nation LIMIT :param_1, you need to ensure that the parameter :param_1 is correctly mapped to a SQL literal in the args array or map. Since the parameter is named, you need to provide a name-value pair to bind the parameter.

Here's how you can resolve it:

1. Ensure Parameter Binding: You need to provide a value for the named parameter :param_1 in the args when executing the query. This can be done by using a map to specify the parameter name and its corresponding value.

2. Example Code:
 

scala
  import org.apache.spark.sql.SparkSession

  val spark = SparkSession
    .builder()
    .appName("Spark named parameter marker example")
    .getOrCreate()

  // Provide the value for the parameter :param_1
  val argMap = Map("param_1" -> 10) // Replace 10 with the desired limit value

  spark.sql(
    sqlText = "SELECT nation.n_nationkey, nation.n_name, nation.n_regionkey, nation.n_comment FROM nation LIMIT :param_1",
    args = argMap
  ).show()
 

By following these steps and ensuring the parameter is properly bound, the UNBOUND_SQL_PARAMETER error should be resolved.