Skip to main content

SQL editor

Database › SQL editor runs SQL against the project database with an editor that knows Postgres.

Run a query​

Type SQL and select Run, or press ⌘/Ctrl+Enter to run the selection (or everything). Results appear in a grid with the row count and duration.

select department, count(*) as requests, sum(amount) as total
from purchase_requests
group by department
order by total desc;

How queries run​

BehaviourDetail
RoleThe project's owner role, so row-level security doesn't filter results
TransactionAll statements run in one transaction
Timeout15 seconds by default (set by the installation); a query that runs longer is cancelled with SQL_TIMEOUT
Rows shownThe first 1,000 rows; the result says when it was truncated
Read-onlyTick Read-only to run in a read-only transaction: writes fail with READ_ONLY

People with read-only access (for example Auditors) always run read-only.

Saved snippets​

Select Save and give the query a name. Saved snippets lists your snippets for this project. Snippets are personal.

Error codes​

CodeMeaning
SQL_TIMEOUTThe query ran longer than the statement timeout
READ_ONLYA write in read-only mode
PERMISSION_DENIEDPostgres refused the operation
SQL_ERRORAny other Postgres error, with its message

From an agent or the API​

  • MCP: run_sql (with a read_only option) and describe_schema.
  • API: POST /api/projects/:name/db/sql with { "sql": "...", "readOnly": true }.

Every query run from the Studio, MCP or the API is audited.

tip

To test what a particular person would see, query as tc_user from server code with tc.db.asUser(req).sql, or check the policies in Database › Policies.

Was this page helpful?