cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
cancel
Showing results for 
Search instead for 
Did you mean: 

Help with Parameters in Databricks SQL

AEW
New Contributor II

I am following the documentation on query parameters (https://docs.databricks.com/sql/user/queries/query-parameters.html) and it's not working for me. I can't get a parameter inserted at the text caret and I can't get cmd + p to work. I've changed spacing around the curly braces, I've added and removed single quotations. I've tried iterations of ctrl + shift + p, ctrl + tab + p, ctrl + alt + p, etc to get the parameter dialogue to pop up.

Here's my text as it stands now:

select EOWinventory, Monday_Date
from snapshot.weekly_inventory_status
where Monday_Date = '{{projection_date}}'

Does anyone have best practices?

1 ACCEPTED SOLUTION

Accepted Solutions

NandiniN
Valued Contributor II
Valued Contributor II

Hello @Anne Walter​ ,

Are you calling this from the sql query editor or a workflow?

Thanks & Regards,

Nandini

View solution in original post

8 REPLIES 8

DD_Sharma
New Contributor III

I think you can try this.

Please try adding a space between the Curly brackets "{ { param_name } } "

User16756723392
New Contributor III
  1. select EOWinventory
  2. from snapshot.weekly_inventory_status
  3. where Monday_Date = '{{projection_date}}' group by Monday_Date

Can you try this

NandiniN
Valued Contributor II
Valued Contributor II

Hello @Anne Walter​ ,

Are you calling this from the sql query editor or a workflow?

Thanks & Regards,

Nandini

AEW
New Contributor II

This was the issue! I wasn't calling it from the sql editor. Thank you!

NandiniN
Valued Contributor II
Valued Contributor II

You do have to put a space between the brackets on either side of the parameter and it should work

{{ schema_name }}

SELECT * FROM {{ schema_table_name }}

Databricks requires that you wrap date and time values in single quotes (')

SELECT *

FROM usage_logs

WHERE date = '{{ date_param }}'

NandiniN
Valued Contributor II
Valued Contributor II

Hello @User16756723392331126896 (Customer)​ ,

I tried this out, I was able to get the text query parameter by default which I changed to date by clicking on the gear button.

Here are a few things -

In mac I typed Control + P (not Command + P)

Param 

When I tried your query, it actually still did not give me a date parameter, but it was text, I clicked on the gear button and changed it to date from drop down.

date 

Using double quotes seems to have solved it.

correct 

I know the document needs update and I will get that going but I hope this helps.

In case it does, please select it as the answer that resolved your issue and let me know if you still face any issue.

Thanks &. Regards,

Nandini

labromb
Contributor

I don't see the need for spaces around the parameter name...

image 

I have just been typing {{param_name}} and it appears automatically in SQL editor

NandiniN
Valued Contributor II
Valued Contributor II

Correct, that was an older workaround, which is now fixed in the later versions, sorry about that.

@Brian Labrom​ if my answer helps, it would be great if you could upvote it or mark is at Best answer to close the loop.

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.