# Get SQL execution details

```{raw} html
<div class="mo-api-page-show-toc" aria-hidden="true"></div>
```

View the complete information for one SQL execution record to confirm its statement text, execution status, duration, and error information. By default, the API returns only records run by the current identity. With the required permission, it can return records for the entire workspace.

```text
POST https://moi.matrixorigin.cn/newmoi/query/detail
```

## Preparation before calling

Prepare a personal access token with access to the current workspace and the [current workspace ID](../../../../guides/ai-studio/resource-center/workspace.md#copy-a-workspace-id). First [list SQL execution records](list-sql-execution-records.md#select-an-sql-execution-record), select the record to analyze, and note its statement ID and execution time.

## Request body

:::::::{div} mo-api-tabs
::::::{tab-set}
:::::{tab-item} Input example

```bash
curl -X POST "https://moi.matrixorigin.cn/newmoi/query/detail" \
  -H "X-API-Key: $AI_STUDIO_API_KEY" \
  -H "X-Workspace-ID: $WORKSPACE_ID" \
  -H 'Content-Type: application/json' \
  -d '{
    "statement_id": "'"$STATEMENT_ID"'",
    "start": "2026-08-26 09:44:00",
    "end": "2026-08-26 09:46:00"
  }'
```

:::::
:::::{tab-item} Parameter description

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| statement_id | string | Yes | Statement ID of the selected SQL execution record. |
| start | string | Yes | Query start time in `YYYY-MM-DD HH:MM:SS` format. |
| end | string | Yes | Query end time in `YYYY-MM-DD HH:MM:SS` format. |
| scope | string | No | View records for the current identity or the current workspace. |

### Read scope

| `scope` value | Records returned | Permission |
| --- | --- | --- |
| self | Records for the current identity. | Default scope. |
| workspace | Workspace-wide records. | Requires workspace audit read permission. |

### Specify a query time range

You must specify both the start and end times, and the range must include the selected record's execution time. This API uses the date-and-time format `YYYY-MM-DD HH:MM:SS` without a time zone. The time displayed in the list includes a time zone, so convert it before entering it here. For example, if the list displays `2026-08-26T09:45:35Z`, you can use the range from `2026-08-26 09:44:00` through `2026-08-26 09:46:00`.

### Use the selected execution record

Enter the selected record's statement ID in the statement ID field, and use a time range that includes the record's execution time for the start and end time fields.

:::::
::::::
:::::::

## Success response

On success, the API returns the matching SQL execution record. If no record matches the range, `data` is `null`; this does not mean that the SQL statement failed.

:::::::{div} mo-api-tabs mo-api-response-tabs
::::::{tab-set}
:::::{tab-item} Response example

```json
{
  "code": "OK",
  "msg": "OK",
  "data": {
    "statement_id": "5c6f22fb-ef0e-4f46-b06f-c31e1a7afb48",
    "transaction_id": "txn-01",
    "session_id": "session-01",
    "account": "acc01",
    "user": "analyst",
    "host": "127.0.0.1",
    "database": "analytics",
    "statement": "SELECT 1 AS n",
    "status": "Success",
    "query_type": "DQL",
    "statement_type": "Select",
    "sql_source_type": "cloud_user_sql",
    "request_at": "2026-08-26T09:45:35Z",
    "response_at": "2026-08-26T09:45:36Z",
    "duration": 1000000,
    "result_count": 1
  }
}
```

:::::
:::::{tab-item} Field details

| Field | Type | Description |
| --- | --- | --- |
| code | string | `OK` on success. |
| msg | string | `OK` on success. |
| data | object | Matching execution record; `null` when no record matches. |
| data.statement_id | string | Statement ID. |
| data.transaction_id | string | Transaction ID. |
| data.session_id | string | Session ID. |
| data.account | string | Account used for execution. |
| data.user | string | Executing user. |
| data.host | string | Execution host. |
| data.database | string | Database used for execution. |
| data.statement | string | SQL statement text. |
| data.statement_tag | string | Statement tag. |
| data.statement_fingerprint | string | Statement fingerprint. |
| data.node_uuid | string | Execution node UUID. |
| data.node_type | string | Execution node type. |
| data.request_at | string | Execution start time. |
| data.response_at | string | Execution end time. |
| data.duration | unsigned integer | Execution duration in nanoseconds. |
| data.status | string | Execution status. |
| data.error_code | string | Error code. |
| data.error | string | Error message. |
| data.exec_plan | string | Stored execution profile. |
| data.rows_read | unsigned integer | Number of rows read. |
| data.bytes_scan | unsigned integer | Number of bytes scanned. |
| data.statement_type | string | Statement type. |
| data.query_type | string | Statement category. |
| data.role_id | unsigned integer | Execution role ID. |
| data.sql_source_type | string | SQL source type. |
| data.result_count | integer | Number of result rows. |
| data.cu | number | Capacity usage. |
| data.connection_id | integer | Database connection ID. |

:::::
::::::
:::::::

## Error response

:::::::{div} mo-api-tabs mo-api-response-tabs
::::::{tab-set}
:::::{tab-item} Response example

```json
{
  "code": "ErrParamInvalid",
  "msg": "Invalid request parameter",
  "data": null
}
```

:::::
:::::{tab-item} Field details

| Field | Type | Description |
| --- | --- | --- |
| code | string | Error code. |
| msg | string | Error message. |
| data | null | — |

:::::
::::::
:::::::

## Next steps

To view the execution profile, use the same statement ID and time range to [get the SQL execution profile](get-sql-execution-profile.md#use-the-selected-execution-record). To run the SQL again, confirm the SQL text, target database, and current identity's permissions, then [execute SQL](../data-processing/sql-execution/execute-sql.md#request-body).
