Run SQL on a branch
Runs a script on one of the branch's Postgres databases on a fresh connection as the database's owner (Admin only), or, with role, as that role: the connection logs in as your own hidden member role on the branch, which can only become the roles you were granted (and what they can become), then runs SET ROLE to role, so a script that resets its role is never the owner. When the run ends (however it ends), its session is ended, whatever the script made as the member role itself is handed to role, and every privilege, default privilege or policy naming the member role is dropped. An Admin acting as a role a member role can't hold (LOGIN, owner-level, or reaching a reserved role) uses the owner's connection and SET ROLE; naming the owner runs as the owner. The script is sent unchanged as one simple query, so multi-statement scripts, explicit transactions and commands like VACUUM work. Unless confirm is true, risky statements (drops, truncates, DELETE/UPDATE without WHERE, also under EXPLAIN ANALYZE or PREPARE, and anything that doesn't parse) and, on a protected branch, every statement that isn't a read are held back with 409 sql_confirm_required. Errors before the connection opens are JSON; then the answer is 200 application/x-ndjson, one JSON event per line: notice, columns (statement, columns: [{name, type}]), rows (statement, at most 200 rows of text-or-null values), complete (statement, tag, rows, truncated: over 1,000 rows), error (statement, code, message, detail, hint, position: 1-based in the sent text), heartbeat (after 15 s without another event) and, always last, done (outcome: ok, error, cancelled, timeout or truncated_response past 10 MiB; duration_ms). Closing the stream cancels the run. Every run is logged with its command tags and a SHA-256 of the script, never the script.
Authorization
bearer In: header
Path Parameters
Database id
uuidBranch id
uuidRequest Body
application/json
TypeScript Definitions
Use the request body type in TypeScript.
POST …/sql's body.
true runs statements the guard would hold back.
The Postgres database; null or absent is the branch's main database.
The role to SET ROLE to first; null or absent runs as the owner.
Chosen by the client; names the run for …/sql/runs/{run_id}/cancel.
uuidThe script, sent as one simple query: 1 byte to 1 MiB.
100 to 900000; 60000 when absent.
int640 <= valueResponse Body
application/x-ndjson
application/json
application/json
application/json
application/json
application/json
application/json
application/json
application/json
application/json
curl -X POST "https://example.com/v1/databases/497f6eca-6276-4993-bfeb-53cbbbba6f08/branches/497f6eca-6276-4993-bfeb-53cbbbba6f08/sql" \ -H "Content-Type: application/json" \ -d '{ "run_id": "dded282c-8ebd-44cf-8ba5-9a234973d1ec", "sql": "string" }'"string"List a role's live sessions GET
The sessions open as the role on the branch's compute right now: the count, and each client's address, `application_name` and start time, oldest first. A read only: when the compute isn't running, the answer is `compute_running: false` with no sessions, and the compute isn't started. Clients that aren't connected at this moment aren't listed. A name with no role has no sessions.
Cancel a SQL run POST
Cancels a run in flight that you started (an Admin may cancel any): Postgres's cancel request is sent and the run's stream ends with `done` (`outcome: cancelled`). Closing the stream cancels too.