Skip to main content

SQL Tasks

Read the Overview first for authentication, request conventions, and errors.

SQL tasks are tasks that you create with CREATE TASK. To list or change SQL tasks, use SQL through the Query API. For task flows that you create in the console, see Task Flows.

Describe a SQL Task​

GET /api/v1/orgs/{orgSlug}/tenant/tasks/{taskName} · Read · Member

ParameterInTypeRequiredDescription
orgSlugpathstringYesOrganization ID.
taskNamepathstringYesTask name.

status is 0 (suspended) or 1 (started). scheduleOptions.scheduleType is 0 (interval, in interval seconds) or 1 (cron, in cron and timeZone).

{
"success": true,
"data": {
"taskID": 1024,
"taskName": "refresh_daily_sales",
"queryText": "INSERT INTO sales.daily SELECT ...",
"owner": "account_admin",
"scheduleOptions": { "cron": "0 2 * * *", "timeZone": "UTC", "scheduleType": 1 },
"warehouseOptions": { "warehouse": "default" },
"nextScheduledAt": "2026-11-10T02:00:00Z",
"status": 1,
"createdAt": "2026-06-01T02:00:00Z",
"updatedAt": "2026-11-01T02:00:00Z"
}
}

Query SQL Task Runs​

POST /api/v1/orgs/{orgSlug}/tenant/tasks-runs/query · Read · Member

FieldTypeRequiredDescription
taskNamestringNoOne task name.
taskNamesstring[]NoSeveral task names.
scheduledTimeStartstringNoStart of the scheduled time range, RFC 3339.
scheduledTimeEndstringNoEnd of the scheduled time range, RFC 3339.
pageintegerNoPage number. Send it with nextPageToken when you go to the next page.
perPageintegerNoRows per page.
nextPageTokenstringNoThe nextPageToken value of the previous response.
previousPageTokenstringNoThe previousPageToken value of the previous response.

Request example:

{
"taskNames": ["refresh_daily_sales"],
"scheduledTimeStart": "2026-11-08T00:00:00Z",
"scheduledTimeEnd": "2026-11-09T00:00:00Z",
"perPage": 50
}

Response example. Task run fields use snake_case. state is a task run state. Page tokens are strings. If nextPageToken is missing, there is no next page.

{
"success": true,
"data": {
"results": [
{
"task_id": 1024,
"task_name": "refresh_daily_sales",
"query_text": "INSERT INTO sales.daily SELECT ...",
"run_id": "7f9c1d2e",
"attempt_number": 1,
"state": 3,
"error_code": 1025,
"error_message": "Unknown table 'orders_tmp'",
"scheduled_time": "2026-11-08T02:00:00Z",
"completed_time": "2026-11-08T02:00:04Z",
"query_id": "01a1b2c3-4d5e",
"warehouse_options": { "warehouse": "default" }
}
],
"nextPageToken": "29319573127561217"
}
}

Types​

Task Run State​

Used by SQL task runs (state) and task flow run history (state).

ValueName
0SCHEDULED
1EXECUTING
2SUCCEEDED
3FAILED
4CANCELLED
Try Databend Cloud for FREE

Multimodal, object-storage-native warehouse for BI, vectors, search, and geo.

Snowflake-compatible SQL with automatic scaling.

Sign up and get $200 in credits.

Try it today