> ## Documentation Index
> Fetch the complete documentation index at: https://deepline.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# ClickHouse Cloud: Clickhouse Run Query

> Run one SQL statement, a read or a write such as an INSERT, on your ClickHouse service and get the result rows. Includes SDK V2 examples, schemas, and cost.

Run one SQL statement, a read or a write such as an INSERT, on your ClickHouse service and get the result rows.

> [!NOTE]
>
> Tool ID: `clickhouse_run_query`

## Run this action

Use the TypeScript SDK for one call. Use `ctx.tools.execute(...)` inside a Play for durable calls, scheduled calls, or CSV processing.

```ts theme={"languages":{"custom":["/languages/deepline-prompt.json"]}}
import { Deepline } from 'deepline';

const deepline = await Deepline.connect();
const result = await deepline.tools.execute(
  'clickhouse_run_query',
  {
    "query": "software companies hiring engineers"
  },
);

console.log(result.toolResponse.raw);
```

### CLI

```bash theme={"languages":{"custom":["/languages/deepline-prompt.json"]}}
deepline run clickhouse_run_query --input '{
  "query": "software companies hiring engineers"
}'
```

## Example response

The SDK returns this shape at `result.toolResponse.raw`. The example values illustrate the response.

```json theme={"languages":{"custom":["/languages/deepline-prompt.json"]}}
{
  "data": {
    "data": {
      "statementKind": "read",
      "rows": [
        {}
      ],
      "rowCount": 123
    },
    "meta": {
      "host": "api.example.com",
      "database": "example",
      "rowLimit": 123
    }
  }
}
```

Use `deepline describe clickhouse_run_query --json` for the latest machine-readable contract.

## Input reference

Runs one SQL statement on the ClickHouse service saved in the connection's SQL interface credentials (SQL service URL, database user and password). SELECT, WITH, SHOW, DESCRIBE, EXPLAIN and EXISTS are reads and return up to rowLimit rows. Every other statement is a write: INSERT, CREATE, ALTER, DELETE, UPDATE, DROP, TRUNCATE and anything Deepline cannot classify. Each call runs once for its run and is never resent after an unknown outcome. An INSERT is sent with insert\_deduplication\_token derived from the call's durable idempotency key and insert\_deduplicate=1, so a retry or replay of the same call within a run is not inserted twice, unless the statement sets insert\_deduplication\_token itself. Pass values only through parameters for ClickHouse \{name:Type} placeholders.

| Name | Type | Required | Default | Details |
| - | - | - | - | - |
| `payload.query` | `string` | Yes | — | One ClickHouse SQL statement. Use \{name:Type} placeholders, such as \{id:UInt64}, for values and pass them in parameters. Do not add a FORMAT clause to a read. Deepline returns rows as JSON. Minimum length: 1. |
| `payload.parameters` | `record` | No | — | Values for the statement's \{name:Type} placeholders, sent as ClickHouse param\_ URL parameters and never written into the SQL text. Strings, numbers and booleans. pass arrays, maps and tuples as a string in ClickHouse text format, such as "\[1,2,3]". |
| `payload.database` | `string` | No | — | Database for unqualified table names. Defaults to the connection's saved default database, then to the database user's default. |
| `payload.rowLimit` | `integer` | No | `5000` | Maximum rows a read returns. data.limited is true when the statement had more rows. Minimum: 1. Maximum: 100000. |
| `payload.timeoutMs` | `integer` | No | `120000` | Request timeout in milliseconds, also sent to ClickHouse as max\_execution\_time. Minimum: 1000. Maximum: 600000. |

<details>
  <summary>Show raw input schema</summary>

  ### Input JSON Schema

  ```json theme={"languages":{"custom":["/languages/deepline-prompt.json"]}}
  {
    "type": "object",
    "description": "Runs one SQL statement on the ClickHouse service saved in the connection's SQL interface credentials (SQL service URL, database user and password). SELECT, WITH, SHOW, DESCRIBE, EXPLAIN and EXISTS are reads and return up to rowLimit rows. Every other statement is a write: INSERT, CREATE, ALTER, DELETE, UPDATE, DROP, TRUNCATE and anything Deepline cannot classify. Each call runs once for its run and is never resent after an unknown outcome. An INSERT is sent with insert_deduplication_token derived from the call's durable idempotency key and insert_deduplicate=1, so a retry or replay of the same call within a run is not inserted twice, unless the statement sets insert_deduplication_token itself. Pass values only through parameters for ClickHouse {name:Type} placeholders.",
    "properties": {
      "query": {
        "type": "string",
        "description": "One ClickHouse SQL statement. Use {name:Type} placeholders, such as {id:UInt64}, for values and pass them in parameters. Do not add a FORMAT clause to a read; Deepline returns rows as JSON.",
        "minLength": 1
      },
      "parameters": {
        "type": "object",
        "description": "Values for the statement's {name:Type} placeholders, sent as ClickHouse param_ URL parameters and never written into the SQL text. Strings, numbers and booleans; pass arrays, maps and tuples as a string in ClickHouse text format, such as \"[1,2,3]\".",
        "additionalProperties": {
          "type": [
            "string",
            "number",
            "boolean"
          ]
        }
      },
      "database": {
        "type": "string",
        "description": "Database for unqualified table names. Defaults to the connection's saved default database, then to the database user's default."
      },
      "rowLimit": {
        "type": "integer",
        "description": "Maximum rows a read returns. data.limited is true when the statement had more rows.",
        "default": 5000,
        "minimum": 1,
        "maximum": 100000
      },
      "timeoutMs": {
        "type": "integer",
        "description": "Request timeout in milliseconds, also sent to ClickHouse as max_execution_time.",
        "default": 120000,
        "minimum": 1000,
        "maximum": 600000
      }
    },
    "required": [
      "query"
    ],
    "additionalProperties": false
  }
  ```
</details>

## Output reference

Standard tool result payload.

| Name | Type | Required | Default | Details |
| - | - | - | - | - |
| `result.data` | `object` | Yes | — | Provider response payload. |
| `result.data.data` | `object` | No | — | — |
| `result.data.data.statementKind` | `"read" \| "write"` | No | — | Allowed: `read`, `write`. |
| `result.data.data.rows` | `array` | No | — | — |
| `result.data.data.rowCount` | `integer` | No | — | — |
| `result.data.data.limited` | `boolean` | No | — | — |
| `result.data.data.columns` | `array` | No | — | — |
| `result.data.data.columns[].name` | `string` | No | — | — |
| `result.data.data.columns[].type` | `string` | No | — | — |
| `result.data.data.writtenRows` | `integer \| null` | No | — | — |
| `result.data.data.writtenBytes` | `integer \| null` | No | — | — |
| `result.data.data.insertDeduplication` | `object \| null` | No | — | — |
| `result.data.data.insertDeduplication.source` | `"deepline" \| "statement" \| "none"` | No | — | Allowed: `deepline`, `statement`, `none`. |
| `result.data.data.insertDeduplication.token` | `string \| null` | No | — | — |
| `result.data.meta` | `object` | No | — | — |
| `result.data.meta.host` | `string` | No | — | — |
| `result.data.meta.database` | `string \| null` | No | — | — |
| `result.data.meta.rowLimit` | `integer` | No | — | — |
| `result.data.meta.timeoutMs` | `integer` | No | — | — |
| `result.meta` | `object` | No | — | Additional response metadata (status, paging). |

<details>
  <summary>Show raw output schema</summary>

  ### Output JSON Schema

  ```json theme={"languages":{"custom":["/languages/deepline-prompt.json"]}}
  {
    "type": "object",
    "description": "Standard tool result payload.",
    "properties": {
      "data": {
        "type": "object",
        "description": "Provider response payload.",
        "properties": {
          "data": {
            "type": "object",
            "properties": {
              "statementKind": {
                "type": "string",
                "enum": [
                  "read",
                  "write"
                ]
              },
              "rows": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": true
                }
              },
              "rowCount": {
                "type": "integer"
              },
              "limited": {
                "type": "boolean"
              },
              "columns": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "name": {
                      "type": "string"
                    },
                    "type": {
                      "type": "string"
                    }
                  },
                  "additionalProperties": false
                }
              },
              "writtenRows": {
                "type": [
                  "integer",
                  "null"
                ]
              },
              "writtenBytes": {
                "type": [
                  "integer",
                  "null"
                ]
              },
              "insertDeduplication": {
                "type": [
                  "object",
                  "null"
                ],
                "properties": {
                  "source": {
                    "type": "string",
                    "enum": [
                      "deepline",
                      "statement",
                      "none"
                    ]
                  },
                  "token": {
                    "type": [
                      "string",
                      "null"
                    ]
                  }
                },
                "additionalProperties": false
              }
            },
            "additionalProperties": false
          },
          "meta": {
            "type": "object",
            "properties": {
              "host": {
                "type": "string"
              },
              "database": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "rowLimit": {
                "type": "integer"
              },
              "timeoutMs": {
                "type": "integer"
              }
            },
            "additionalProperties": false
          }
        },
        "additionalProperties": false
      },
      "meta": {
        "type": "object",
        "description": "Additional response metadata (status, paging).",
        "additionalProperties": true
      }
    },
    "required": [
      "data"
    ],
    "additionalProperties": false
  }
  ```
</details>

## Deepline cost

* Pricing model: `fixed` (per call).
* Estimated Deepline credits: `0` per pricing unit.
* Provider-native pricing may still exist outside Deepline credit billing.

## Related documentation

* [Connect integrations](https://deepline.com/docs/integrations.md)
* [SDK V2 quickstart](https://deepline.com/docs/sdk-v2/quickstart.md)
* [SDK reference](https://deepline.com/docs/sdk-v2/sdk-reference.md)
* [Run tools across a CSV](https://deepline.com/docs/sdk-v2/batch-csv.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.