# View execution result

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

View the data returned by your successful SQL execution.

If there are many results, you can read them in several times: `offset` indicates how many previous rows to skip, and `limit` indicates how many rows can be read at most this time. For example, use `offset: 0, limit: 20` to read the first 20 lines; then use `offset: 20, limit: 20` to read the next 20 lines.

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

## Preparation before calling

First [query the execution status](get-execution-status.md), confirm that the status is `success` and obtain the result ID (`statement_id`). This interface can only read queries successfully executed by the current identity.


## Request body

::::{div} mo-api-split
:::{div} mo-api-split-main

```{raw} html
<dl class="mo-api-fields">
  <div class="mo-api-field"><dt><code>statement_id</code><span class="mo-api-field__type">string</span><span class="mo-api-field__required">Required</span></dt><dd>The result ID of a successful query execution.</dd></div>
  <div class="mo-api-field"><dt><code>offset</code><span class="mo-api-field__type">integer</span></dt><dd>The row position to start reading, starting from 0.</dd></div>
  <div class="mo-api-field"><dt><code>limit</code><span class="mo-api-field__type">integer</span></dt><dd>The maximum number of rows returned this time; when 0 is not provided or is less than or equal to 0, the server uses 1000.</dd></div>
</dl>
```

:::
:::{div} mo-api-split-aside

```{raw} html
<p class="mo-api-example-label">Request example</p>
```

```bash
curl -X POST "https://moi.matrixorigin.cn/newmoi/query/result" \
  -H "X-API-Key: $AI_STUDIO_API_KEY" \
  -H "X-Workspace-ID: $WORKSPACE_ID" \
  -H 'Content-Type: application/json' \
  -d "{\"statement_id\":\"$STATEMENT_ID\",\"offset\":0,\"limit\":20}"
```

:::
::::

## Successful response

`total` is the number of rows returned this time, not the total number of rows in the complete result set. Each row in `result` is arranged in the order of `columns`; `Valid` is `false`, which means that the cell is `NULL`.


The response fields are as follows.

In this document, `[]` after a type denotes an array. In a field path, `[]` denotes each item in an array; for example, `data.columns[].name` is the `name` field of each item in the `data.columns` array.

::::{div} mo-api-split
:::{div} mo-api-split-main

```{raw} html
<dl class="mo-api-fields">
  <div class="mo-api-field"><dt><code>code</code><span class="mo-api-field__type">integer</span></dt><dd>200 on success.</dd></div>
  <div class="mo-api-field"><dt><code>data.query_id</code><span class="mo-api-field__type">string</span></dt><dd>The ID of the query that produced the result.</dd></div>
  <div class="mo-api-field"><dt><code>data.db_name</code><span class="mo-api-field__type">string</span></dt><dd>The database specified during execution.</dd></div>
  <div class="mo-api-field"><dt><code>data.statement_id</code><span class="mo-api-field__type">string</span></dt><dd>Statement ID of this result.</dd></div>
  <div class="mo-api-field"><dt><code>data.status</code><span class="mo-api-field__type">string</span></dt><dd>success when the result is successfully read.</dd></div>
  <div class="mo-api-field"><dt><code>data.offset</code><span class="mo-api-field__type">integer</span></dt><dd>The row position where reading starts this time.</dd></div>
  <div class="mo-api-field"><dt><code>data.limit</code><span class="mo-api-field__type">integer</span></dt><dd>The maximum number of rows returned for this request.</dd></div>
  <div class="mo-api-field"><dt><code>data.total</code><span class="mo-api-field__type">integer</span></dt><dd>The number of rows actually returned this time.</dd></div>
  <div class="mo-api-field"><dt><code>data.columns[].name</code><span class="mo-api-field__type">string</span></dt><dd>Column name.</dd></div>
  <div class="mo-api-field"><dt><code>data.columns[].type</code><span class="mo-api-field__type">string</span></dt><dd>The column type returned by the database.</dd></div>
  <div class="mo-api-field"><dt><code>data.result[][].String</code><span class="mo-api-field__type">string</span></dt><dd>The string value of the cell.</dd></div>
  <div class="mo-api-field"><dt><code>data.result[][].Valid</code><span class="mo-api-field__type">boolean</span></dt><dd>Whether it is a non-NULL value.</dd></div>
</dl>
```

:::
:::{div} mo-api-split-aside

```{raw} html
<p class="mo-api-example-label">Successful response example</p>
```

```json
{
  "code": 200,
  "data": {
    "query_id": "query_01",
    "db_name": "sales",
    "statement_id": "statement_01",
    "status": "success",
    "offset": 0,
    "limit": 20,
    "total": 1,
    "columns": [
      {"name": "n", "type": "INT64"}
    ],
    "result": [
      [{"String": "1", "Valid": true}]
    ]
  }
}
```

:::
::::

## Error response

::::{div} mo-api-split
:::{div} mo-api-split-main

```{raw} html
<dl class="mo-api-fields">
  <div class="mo-api-field"><dt><code>code</code><span class="mo-api-field__type">string</span></dt><dd>Error code.</dd></div>
  <div class="mo-api-field"><dt><code>msg</code><span class="mo-api-field__type">string</span></dt><dd>Readable error message.</dd></div>
  <div class="mo-api-field"><dt><code>data</code><span class="mo-api-field__type">null</span></dt><dd>`null` in an error response.</dd></div>
</dl>
```

:::
:::{div} mo-api-split-aside

```{raw} html
<p class="mo-api-example-label">Error response example</p>
```

```json
{"code": 404, "message": "SQL 查询结果不存在"}
```

:::
::::

## Follow-up operations

Continue to adjust `offset` and `limit` to read subsequent lines, or [download execution results](download-execution-result.md).
