CREATE JOB creates a SQL job in the SUSPENDED state. Use OR REPLACE to update an existing SQL job. Use ALTER JOB ... RESUME to start scheduled runs.

​
Syntax

{ CREATE JOB [ IF NOT EXISTS ] | CREATE OR REPLACE JOB } <name>
  { SCHEDULE = '<schedule>' [ RESOURCE_GROUP = '<resource_group>' ]
  | RESOURCE_GROUP = '<resource_group>' SCHEDULE = '<schedule>' }
  AS <statement>;

​
Required parameters

ParameterDescription
<name>A SQL identifier unique among the environment’s SQL jobs and the scheduled jobs in its active deployment.
<schedule>A Chalk duration such as 1m or a five-field UTC cron expression such as 0 9 * * *.
<statement>One Chalk SQL statement to run each time the job fires.

​
Optional parameters

ParameterDescription
IF NOT EXISTSReturns the existing SQL job with the same name. If the name is available, creates a suspended job.
OR REPLACELets the job creator update the statement, schedule, and resource group while preserving run history and the active or suspended state. If the name is available, creates a suspended job. Each run reads the job statement when it submits the query.
RESOURCE_GROUPThe resource group for async SQL execution. If omitted, the job uses the environment’s default group.

​
Return values

The command returns one row describing the resulting schedule with the columns of chalk.jobs.

​
Permissions

Creating or replacing a SQL job requires query.online, cron.create, and workflow.manage in the environment. Returning an existing SQL job with IF NOT EXISTS also requires workflow.read.

​
Examples

Create a job scheduled for 09:00 UTC every day.

CREATE JOB morning_report
  SCHEDULE = '0 9 * * *'
  AS SELECT 42 AS answer;

Update the job to run at 10:00 UTC every day.

CREATE OR REPLACE JOB morning_report
  SCHEDULE = '0 10 * * *'
  AS SELECT 42 AS answer;

​
See also