Run a read-only SQL query
pg_queryRun one read-only SQL query and return its rows safely, with statement validation, parameter binding, and row/cell limits to prevent unsafe or excessive results.
Instructions
Run one read-only SQL query (SELECT, WITH, VALUES, TABLE, SHOW) and return the rows.
The query is checked before it runs: one statement only, no writes, no functions with
side effects, protected tables and columns respected, and always inside a read-only
transaction with a time limit. Pass values through params ($1, $2, ...) instead of
concatenating them into the SQL.
Results are limited: max_rows (default from the connection, typically 200) and long
values are cut at max_cell_chars. When has_more is true, narrow the query or page
with offset. Prefer explicit column lists and a WHERE clause on large tables.
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": {
"sql": "<sql>"
},
"name": "pg_query"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sql | Yes | ||
| format | No | json | |
| offset | No | ||
| params | No | ||
| max_rows | No | ||
| connection | No | ||
| max_cell_chars | No |