execute_sql
Execute SQL queries with parameterized statements to prevent injection. Supports transactions, multiple statements, and schema hints for database management.
Instructions
Execute SQL queries. Supports SELECT, INSERT, UPDATE, DELETE (if not in readonly mode). Use $1, $2 placeholders with params array to prevent SQL injection. Use allowMultipleStatements to run multiple statements separated by semicolons. Use transactionId to run within a transaction. Optionally use server/database/schema params for one-time execution on a different server without changing the main connection.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sql | Yes | SQL statement(s). Use $1, $2, etc. for parameterized queries. | |
| params | No | Parameters for $1, $2, etc. placeholders (e.g., [123, 'value']). Not supported with allowMultipleStatements. | |
| maxRows | No | Max rows to return (default: 1000, max: 100000) | |
| offset | No | Skip rows for pagination | |
| allowLargeScript | No | Bypass 100KB SQL limit for deployment scripts | |
| includeSchemaHint | No | Include schema info (columns, PKs, FKs) for tables in the query. | |
| allowMultipleStatements | No | Allow multiple SQL statements separated by semicolons. Returns results for each statement. | |
| transactionId | No | Execute within an active transaction. Get this from begin_transaction. | |
| maxEstimatedRows | No | SP-7 query budget: refuse to run if the planner estimates more than this many rows. Pre-EXPLAIN check on read-only queries only. Useful as a backstop for AI-generated queries. | |
| maxEstimatedCost | No | SP-7 query budget: refuse to run if the planner estimates total cost above this. Read-only queries only. | |
| server | No | One-time server override. Execute on this server without changing main connection. Cannot be used with transactionId. | |
| database | No | One-time database override. Uses this database for execution without changing main connection. | |
| schema | No | One-time schema override. Sets search_path for this execution only. |