run_query
Execute read-only SQL queries to fetch PostgreSQL rows, blocking writes and returning result sets.
Instructions
Execute a read-only SELECT and return the rows.
Use this once you know which tables and columns you need. If you do not yet know, call search_schema first rather than guessing table names; a query against a table that does not exist wastes a round trip.
Only a single SELECT is accepted. WITH is fine as long as the whole statement is read-only. Anything else, including INSERT/UPDATE/DELETE, DDL, statement stacking, and DML hidden inside a CTE, is rejected before it reaches the database.
On failure:
"Blocked: ..." means the statement violated the read-only policy. The message names the offending construct. Rewrite as a plain SELECT; do not retry the same statement.
A syntax or "column does not exist" error means the schema assumption was wrong. Call describe_table on the table in question and correct the column names rather than guessing again.
A statement timeout means the query was too expensive. Call explain_query to see the plan, then add a WHERE clause or aggregate.
Results are capped. When truncated is true the rows shown are a prefix, not the answer; narrow the query instead of treating them as complete.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sql | Yes | ||
| max_rows | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| note | No | Set when truncated, explaining how to narrow the query. | |
| rows | Yes | Row-major values, aligned with columns. | |
| columns | Yes | ||
| row_count | Yes | Number of rows returned, after any truncation. | |
| truncated | Yes | True when the result hit max_rows and more rows exist. |