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.
4 REPLIES 4

feiyun0112
Contributor III
# 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
Valued Contributor
Valued Contributor

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".


Kaniz_Fatma
Community Manager
Community Manager

Hey there! Thanks a bunch for being part of our awesome community! 🎉 

We love having you around and appreciate all your questions. Take a moment to check out the responses – you'll find some great info. Your input is valuable, so pick the best solution for you. And remember, if you ever need more help , we're here for you! 

Keep being awesome! 😊🚀

 

Join 100K+ Data Experts: Register Now & Grow with Us!

Excited to expand your horizons with us? Click here to Register and begin your journey to success!

Already a member? Login and join your local regional user group! If there isn’t one near you, fill out this form and we’ll create one for you to join!