# Query table information

Query table definition, table creation SQL, statistics and other information.

```text
POST $CLOUDSIGMA_API_BASE/catalog/table/info
```

## Before you call this API

Configure the [regional API endpoint and authentication](https://omnifabric.cloudsigma.com/docs/developer/endpoints-and-authentication.html.md), and select the target workspace.

First [query the object](https://omnifabric.cloudsigma.com/docs/reference/api/ai-studio/resource-center/catalog/list-database-objects.html.md) in the database to obtain the target table ID, or prepare the table name and database positioning parameters.

Set the operation-specific values used in the request:

- `$TABLE_ID`: The table ID to be queried.

## Request example

```bash
curl -X POST "$CLOUDSIGMA_API_BASE/catalog/table/info" \
  -H "X-API-Key: $CLOUDSIGMA_API_KEY" \
  -H "X-Workspace-ID: $WORKSPACE_ID" \
  -H 'Content-Type: application/json' \
  -d '{
    "id": '"$TABLE_ID"'
  }'
```

## Request body

The request can be queried by table ID, or by table name plus database ID/system database name.

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer | Conditionally required | Table ID. You do not need to pass the name after providing it. |
| `name` | string | Conditionally required | Table name; required if `id` is not provided. |
| `database_id` | integer | Conditionally required | Database ID of non-system database; mutually exclusive with `database_name`. |
| `database_name` | string | Conditionally required | System database name; mutually exclusive with `database_id`. |
| `include_stats` | boolean | No | Whether to return column statistics. |

## Successful response

Returns `200` and table information on success. Returns `403` when there is no read permission.

```json
{
  "code": "OK",
  "msg": "OK",
  "data": {
    "name": "orders",
    "lines": 120,
    "size": 4096,
    "created_at": 1735689600,
    "updated_at": 1735689600,
    "created_by": "user@example.com",
    "description": "订单表",
    "comment": "订单明细",
    "columns": [
      {
        "name": "id",
        "type": "INT",
        "is_pk": true
      }
    ],
    "create_sql": "CREATE TABLE orders (id INT PRIMARY KEY)",
    "stats": [
      {
        "name": "id",
        "type": "INT",
        "max_value": "100",
        "min_value": "1"
      }
    ]
  }
}
```

The response fields are as follows.

| Field | Type | Description |
| --- | --- | --- |
| `code` | string | `OK` on success. |
| `msg` | string | `OK` on success. |
| `data.name` | string | Table name. |
| `data.lines` | integer | Number of table rows. |
| `data.size` | integer | Table size in bytes. |
| `data.created_at` | integer | Unix timestamp of creation time in seconds. |
| `data.updated_at` | integer | Unix timestamp of the update time in seconds. |
| `data.created_by` | string | Creator ID. |
| `data.description` | string | Table description. |
| `data.comment` | string | Table comment. |
| `data.columns` | array | Column definition. Each item contains `name`, `type`, and may contain `is_pk`, `comment`, `precision`, `default`. |
| `data.create_sql` | string | Create table SQL. |
| `data.stats` | array | Column statistics; each item includes column name, type, primary key identifier, default value, comment, and maximum and minimum values. |

## Error response

```json
{
  "code": "ErrParamInvalid",
  "msg": "表定位参数无效",
  "data": null
}
```

### Common HTTP errors

```{list-table}
:header-rows: 1
:widths: 12 22 32 34

* - HTTP status code
  - error code
  - Common causes
  - Recommended actions
* - `400`
  - `ErrParamInvalid`
  - No valid table positioning method is provided, or `database_id` and `database_name` are passed in at the same time.
  - Use a table ID, or just a name targeting method.
* - `403`
  - `ErrForbidden`
  - The current identity does not have table read permission.
  - Check workspace and table authorizations.
* - `409`
  - `ErrReadonlySystemDatabase`
  - The system database does not support the current read path.
  - Use supported table positioning methods instead.
* - `500`
  - `ErrServer`
  - The service cannot read table information.
  - Record the request time and error message and try again; if it continues to fail, contact support.
```

## Follow-up operations

When modifications are needed [Update database](https://omnifabric.cloudsigma.com/docs/reference/api/ai-studio/resource-center/catalog/update-database.html.md). When returning the list [Query file products](https://omnifabric.cloudsigma.com/docs/reference/api/ai-studio/resource-center/catalog/list-file-artifacts.html.md).
