Run SQL
queryRun one SQL statement to answer data questions: select columns, join tables, filter, sort, and group rows. Read-only unless writes are enabled; returns rows or affected counts.
Instructions
Run exactly ONE SQL statement — the general tool for answering questions: specific columns, JOINs (follow fk from describe), filters, sorting, GROUP BY. Read-only connections accept only SELECT/SHOW/DESCRIBE/EXPLAIN/WITH/VALUES/TABLE (+PRAGMA on SQLite); multiple statements are refused. Prefer sample/count for simple peeks and totals, explain for performance. A LIMIT is added automatically when missing. Returns rows[N]{columns} plus rows, truncated (true = more rows exist — narrow with WHERE or raise limit) and ms; write statements (only if writes are enabled) return affected instead. On failure returns isError with 'error: ' (e.g. refused statement, unknown table, SQL error).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sql | Yes | A single SQL statement in the connection's dialect, without a trailing ';' chain. | |
| limit | No | Max rows (default 100; capped by settings, usually 200). | |
| format | No | Result format. Default from settings: toon (compact table: rows[N]{cols}: then one line per row). | |
| database | No | Optional database to use instead of the connection's default (names from `databases`). Omit to use the default. | |
| connection | Yes | Connection name exactly as returned by `connections` (e.g. "shop"). Unknown or unexposed names return an error. |