cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
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
Databricks Employee
Databricks Employee

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
Databricks Employee
Databricks Employee
  1. select EOWinventory
  2. from snapshot.weekly_inventory_status
  3. where Monday_Date = '{{projection_date}}' group by Monday_Date

Can you try this

NandiniN
Databricks Employee
Databricks Employee

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
Databricks Employee
Databricks Employee

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
Databricks Employee
Databricks Employee

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
Databricks Employee
Databricks Employee

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.

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