Export query results
export_query_resultsRun SQL on one connection and return the whole result as a file body in CSV, JSON or XLSX. Use it when the user wants a file to download, attach or load into another tool, or needs more rows than execute_query returns (10000 at most). To read or analyse rows yourself, use execute_query instead: it is smaller and returns structured rows. For a recurring export to Google Sheets or Slack, use create_schedule. On PostgreSQL and MySQL, omitting limit exports every row the query returns, bounded only by the query timeout; other engines stop at 100000 rows. Always reads the database, never the result cache. Read-only: only a single SELECT, WITH or EXPLAIN statement is accepted. Refused on an approved_queries connection. Counts against the company's monthly query quota and a limit of 30 queries per minute (the team can set a lower one per connection). Needs the execute scope and a member role that can edit. CSV and JSON come back as text; XLSX comes back base64-encoded. The team can require a person to approve some requests: the call then fails with code APPROVAL_REQUIRED and an approvalUrl. Show the user that link, wait until they say it is approved, then repeat the exact same call with approvalId. An approval works once, for that SQL, within 30 minutes.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"connectionId": "<connectionId>",
"sql": "<sql>",
"format": "<format>"
},
"name": "export_query_results"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sql | Yes | The SQL whose result to export, in the connection's own dialect. | |
| limit | No | Maximum rows, up to 100000. Omit on PostgreSQL and MySQL to export every row; other engines then default to 100000. | |
| format | Yes | csv for spreadsheets and other tools, json for programs, xlsx for an Excel file (returned base64-encoded). | |
| approvalId | No | Only when repeating a call that came back with APPROVAL_REQUIRED, after the user approved it. Send the same arguments again. | |
| connectionId | Yes | Connection id from list_connections. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| format | Yes | ||
| content | Yes | The file body: CSV or JSON text, or base64 for xlsx. | |
| truncated | No | True when a row limit or memory cap cut the file short. |