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: 

pass a tuple as parameter to sql query

kll
New Contributor III
at_lst = ['131','132','133']

at_tup = (*at_lst,)
 
print(at_tup)
('131','132','133')<div> <div><span>In my sql query, i am trying to pass this on a parameter, however, it doesn't work. <div> <div><div><div><span>%sql<br /><div><span>select * from main.schema.tbl<div><span>where code IN <span>( '{{ at_tup }}' )<div> <div><span>^ This return no result. <div> <div><span>However, when I pass the actual tuple, i get the desired results: <div> <div><div><span>select * from main.schema.tbl<div><span>where code IN ('131','132','133')<div> <div>How do I pass a tuple as a paramter the sql query?</div></div></span></div></span></div></div></div></span></div></div></span></div></div></span></span></div></span></div></span></div></div></div></div></span></div></div>
1 REPLY 1

kll
New Contributor III

@Retired_mod  I am writing sql using the magic command in the cell block, `%%sql`. Is there a way to pass a parameter in the query without using the `execute` method of the cursor object? Can you please share an example?