<span id="查询指定表的列名"></span>

# Get table column names

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

Query column names of a table in a specified database for field selection.

```text
POST https://api.moi.matrixorigin.cn/v5/table/columns
```

<span id="调用前准备"></span>

## Before you call this API

`BASE_URL` uses the product API prefix `https://api.moi.matrixorigin.cn/v5`. For a dedicated deployment, use its corresponding product API address.

Obtain database ID and table name, or a table ID in that database. Prepare a personal access token with workspace/table read access and a workspace ID. `BASE_URL` includes the same environment's product prefix. `MOI_KEY` and `WORKSPACE_ID` are product credentials and workspace ID. Example IDs/data are placeholders.

<span id="请求体"></span>

## Request body

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

```bash
curl --fail-with-body -sS -X POST "$BASE_URL/table/columns" \
  -H "X-API-Key: $MOI_KEY" \
  -H "X-Workspace-ID: $WORKSPACE_ID" \
  -H "Content-Type: application/json" \
  -d '{"database_id": 10, "table_name": "orders"}'
```

Omit table_name when reading by table ID.

```bash
curl --fail-with-body -sS -X POST "$BASE_URL/table/columns" \
  -H "X-API-Key: $MOI_KEY" \
  -H "X-Workspace-ID: $WORKSPACE_ID" \
  -H "Content-Type: application/json" \
  -d '{"database_id":10,"table_id":31}'
```

:::::
:::::{tab-item} Parameters

| Fields | Type | Required | Description |
| --- | --- | --- | --- |
| `database_id` | integer | Yes | Positive integer database ID. |
| `table_name` | string | Conditional | Nonempty names take precedence over table_id. |
| `table_id` | integer | Conditional | Positive table ID when table_name is empty; must belong to database_id. |

Returns column names only, not types or CREATE statements. ID lookup validates database ownership.

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

<span id="成功响应"></span>

## Successful response

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

```json
{
  "code": "OK",
  "msg": "OK",
  "data": {
    "db_name": "sales",
    "table_name": "orders",
    "col_names": [
      "id",
      "amount"
    ]
  }
}
```

:::::
:::::{tab-item} Fields

| Field | Type | Description |
| --- | --- | --- |
| `code` | string | OK on success. |
| `msg` | string | OK on success. |
| `data.db_name` | string | Database name. |
| `data.table_name` | string | Actual queried table name. |
| `data.col_names` | string[] (array of strings) | Column names; may be null without columns. |

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

<span id="错误响应"></span>

## Error response

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

```json
{
  "code": "ErrParamInvalid",
  "msg": "示例错误信息"
}
```

:::::
:::::{tab-item} Fields

| HTTP | code | Condition |
| --- | --- | --- |
| 400 | ErrParamInvalid | Invalid database ID or table locator. |
| 404 | ErrNotFound | Table missing, ID outside the database, or physical table not found. |

Use actual returned code, msg, and diagnostic fields for identity, permission, and dependency failures. Error text may vary by language.

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