cancel
Showing results for 
Search instead for 
Did you mean: 
Generative AI
Explore discussions on generative artificial intelligence techniques and applications within the Databricks Community. Share ideas, challenges, and breakthroughs in this cutting-edge field.
cancel
Showing results for 
Search instead for 
Did you mean: 

Error - Interact with SQL database

dileepkumar_t
New Contributor

 

When I try to use Datbricks sql agent, I'm getting below error:

DatabaseError: (databricks.sql.exc.ServerOperationError) [UNBOUND_SQL_PARAMETER] Found the unbound parameter: param_1. Please, fix `args` and provide a mapping of the parameter to a SQL literal.; line 3 pos 7 [SQL: SELECT nation.n_nationkey, nation.n_name, nation.n_regionkey, nation.n_comment FROM nation LIMIT :param_1] [parameters: {'param_1': 3}]

Can someone help me? #https://docs.databricks.com/en/large-language-models/langchain.html ##

Databricks SQL Agent

 

1 REPLY 1

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.

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group