cancel
Showing results for 
Search instead for 
Did you mean: 
Get Started Discussions
Start your journey with Databricks by joining discussions on getting started guides, tutorials, and introductory topics. Connect with beginners and experts alike to kickstart your Databricks experience.
cancel
Showing results for 
Search instead for 
Did you mean: 

[UNBOUND_SQL_PARAMETER] When running Placeholder query

AadityaBhatt
New Contributor II

I am using the databricks-sql-go library version 1.5.2. I am trying to run a query with placeholders of type '?'

The query looks like 

params, args := databricksParams(values)
sql := fmt.Sprintf(`SELECT COUNT(*) FROM %s.%s WHERE %s IN (%s)`, schema, table, column, strings.Join(params, ", "))
res, err := conn.Exec(sql, args...)
where params is nothing but a slice of '?' and args are the values I want to query.
I am getting the error
[UNBOUND_SQL_PARAMETER] Found the unbound parameter: _58. Please, fix `args` and provide a mapping of the parameter to a SQL literal.; line 1 pos 58
I have tried with $1,$2 type placeholders as well. Is this not supported with Databricks or am I doing something incorrectly.
3 REPLIES 3

feiyun0112
Honored Contributor
# Query parameters

Passing parameters to a query is supported when run against servers with version DBR 14.1.

	p := dbsql.Parameter{Name: "p_bool", Value: true},
	rows, err1 := db.QueryContext(ctx, `select * from sometable where condition=:p_bool`,dbsql.Parameter{Name: "p_bool", Value: true})

databricks-sql-go/doc.go at main · databricks/databricks-sql-go (github.com)

AadityaBhatt
New Contributor II

This works fine when I have to pass just 1 argument. But how will this work where I have n number of values to pass inside an IN clause?

SergeRielau
Databricks Employee
Databricks Employee

Can you print out an example after the Sprintf substitutions?
It seems you generated a query with a named parameter: ":_58" But args (which should be a Map) does not have a key named "_58".


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