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

Automate in code the launching of a sql script

marta_cdc
New Contributor

Do you know how to automate in code the launching of a sql script?

Currently I do it by selection. 

image

4 REPLIES 4

-werners-
Esteemed Contributor III

@Marta Vicente Sánchez​, what tool are you using here? And are we talking about Databricks SQL?

Kaniz
Community Manager
Community Manager

Hi @Marta Vicente Sánchez​, You can use scheduled query executions to update your dashboards or enable routine alerts. By default, your queries do not have a schedule.

Note:-

If an alert uses your query, it runs on its refresh schedule and does not use the query schedule.

  • To set the schedule: Click the query info tab.

image 

  • Click the link to the right of Refresh Schedule to open a picker with scheduled intervals.

image 

  • Set the schedule.

The picker scrolls and allows you to choose:

  • An interval: 1-30 minutes, 1-12 hours, 1 or 30 days, 1 or 2 weeks
  • A time. The time selector displays in the picker only when the interval is greater than one day and the day selection is greater than one week. When you schedule a specific time, Databricks SQL takes input in your computer’s timezone and converts it to UTC. You must adjust the picker by your local offset if you want a query to run at a particular time in UTC. For example, if you want a question to execute at 00:00 UTC each day, but your current timezone is PDT (UTC-7), you should select 17:00 in the selector:

image 

  • Click OK.

  • Your query will run automatically.

  • If you experience a scheduled query not executing according to its schedule, you should manually trigger the query to ensure it doesn’t fail. However, you should be aware of the following:
    • If you schedule an interval—for example, “every 15 minutes”—the interval is calculated from the last successful execution. If you manually execute a query, the scheduled query will not be executed until the interval has passed.
    • If you schedule a time, Databricks SQL waits for the results to be “outdated.” For example, suppose you have a query set to refresh every Thursday and manually execute it on Wednesday. In that case, the results will still be considered “valid” by Thursday so that the query wouldn’t be scheduled for a new execution. Thus, for example, when setting a weekly schedule, check the last query execution time and expect the scheduled query to be executed on the selected day after that execution is a week old. Make sure not to execute the query during this time manually.

  • If a query execution fails, Databricks SQL retries with a back-off algorithm. The more failures, the further away the next retry will be (which might be beyond the refresh interval).

Query failure reports

If one or more queries fails, Databricks SQL notifies query owners by email once per hour. These emails continue until there are no more failures. Failure report emails run on an independent process from the actual query schedules. It may take up to an hour after a failed query execution before Databricks SQL sends the failure report.

If query owners do not receive emailed failure reports when scheduled queries fail, your administrator has disabled them for your Databricks SQL instance.

Kaniz
Community Manager
Community Manager

Hi @Marta Vicente Sánchez​ , We haven’t heard from you on the last response from me, and I was checking back to see if you have a resolution yet. If you have any solution, please share it with the community as it can be helpful to others. Otherwise, we will respond with more details and try to help.

Hi @Marta Vicente Sánchez​,

Just a friendly follow-up. Did any of the responses help you to resolve your question? if it did, please mark it as best. Otherwise, please let us know if you still need help.

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.