Chalk SQL
Create, test, and manage recurring Chalk SQL jobs and inspect their results in SQL history.
A scheduled SQL job runs one Chalk SQL statement asynchronously on a recurring schedule. Chalk stores the job in your environment across deployments and runs its statement with the current permissions of the user or service token that created it.
In the SQL Explorer, set the worksheet datasource to Chalk SQL. Select one statement at a time and choose Run async. If the example name is already in use, replace it throughout the walkthrough.
Create a job whose statement returns 42 without reading or writing application data.
CREATE JOB scheduled_sql_demo
SCHEDULE = '1m'
AS SELECT 42 AS answer;
Use a Chalk duration such as 1m or a five-field UTC cron expression such as 0 9 * * *.
To run on a specific resource group, add
RESOURCE_GROUP = 'analytics' before AS, using a group in your environment. When you omit
the clause, the job uses the environment’s default resource group.
See the CREATE JOB syntax for the full grammar.
Query chalk.jobs to find the new
job. Confirm that its kind is sql and its state is SUSPENDED.
SELECT name, kind, schedule, state, created_at
FROM chalk.jobs
WHERE name = 'scheduled_sql_demo';
Trigger a run while the schedule is suspended. AWAIT waits for the run to finish. A successful
command returns the schedule run’s run_id and a state of COMPLETED. A failed, skipped, or
canceled run raises a SQL error with the run ID. Omit AWAIT to return as soon as the scheduler
accepts the run.
EXECUTE JOB scheduled_sql_demo AWAIT;
In the dashboard, open Offline > Schedules and select the job. In Run history, find the
Manual run and select View query to see answer = 42 in SQL history. The link uses
the run’s SQL operation ID. Each run gets one attempt to submit the query and one attempt to
execute it.
ALTER JOB scheduled_sql_demo RESUME;
Query chalk.jobs again and confirm that the state is ACTIVE. After the next firing, look
for a Scheduled run with a status of Completed in the job’s run history. Chalk skips a
scheduled firing if a previous run is still open. You can manually trigger a run while another
run is in progress.
Suspend the schedule and query chalk.jobs again to confirm the state is SUSPENDED.
If Chalk records a scheduled trigger while the schedule is paused, it appears as Skipped
in run history.
ALTER JOB scheduled_sql_demo SUSPEND;
After inspecting the run history, optionally drop the job. Dropping it stops future triggers and preserves its run records.
DROP JOB scheduled_sql_demo;
To change the resource group of a job you plan to keep, run
ALTER JOB scheduled_sql_demo SET RESOURCE_GROUP = 'analytics'.
Each job statement reference lists the permissions for that command.
Viewing SQL job run history requires workflow.read.