---
title: "Run a statement (SQL, a MongoDB command document or Redis commands) or browse tables/rows; audited"
method: POST
path: "/databases/{databaseId}/console/{sessionId}/run"
tags: ["Databases"]
---

# Run a statement (SQL, a MongoDB command document or Redis commands) or browse tables/rows; audited

`POST /databases/{databaseId}/console/{sessionId}/run`

## Request

- Base URL: `https://hostingsurge.com/api/v1`
- URL: `https://hostingsurge.com/api/v1/databases/{databaseId}/console/{sessionId}/run`
- Auth: one of:
  - HTTP bearer
  - API key in cookie `__Host-hs_session`

## Path parameters

- `databaseId` string, uuid, required
- `sessionId` string, uuid, required

## Request body

- union
  - object
    - `kind` 'statement', required
    - `text` string, required
    - `maxRows` integer
  - object
    - `kind` 'tables', required
    - `filter` string: name filter (Redis: a MATCH pattern such as user:*)
    - `cursor` string: continue a Redis key listing (nextCursor of the previous page)
  - object
    - `kind` 'rows', required
    - `table` object, required
      - `schema` string, nullable: schema (PostgreSQL), database (MySQL/MariaDB/MongoDB) or logical database number (Redis)
      - `name` string, required: table, view or collection name, or the Redis key
    - `limit` integer
    - `offset` integer

## Response `200`

Result

- object
  - `sessionId` string, uuid, required
  - `kind` 'statement' | 'tables' | 'rows', required
  - `mode` 'read' | 'write', required
  - `ok` boolean, required: false when a statement failed; the failing result set carries the error
  - `durationMs` integer, required
  - `results` object[], required
    - `kind` 'rows' | 'command' | 'error', required
    - `command` string, nullable, required: command tag, e.g. "SELECT 3", "UPDATE 2", "OK"
    - `columns` object[], required
      - `name` string, required
      - `type` string, nullable, required
    - `rows` array[], required: values as text; null is SQL NULL / a missing field
      - string[]
    - `rowCount` integer, nullable, required: rows returned or affected
    - `truncated` boolean, required: more rows existed than were returned (maxRows), or long values were shortened
    - `error` object, nullable, required
      - `message` string, required
      - `code` string, nullable, required
      - `position` integer, nullable, required
  - `tables` object[], nullable, required: for kind "tables"
    - `schema` string, nullable, required
    - `name` string, required
    - `type` string, required: table, view, materialized view, collection, or the Redis type (string, hash, list, set, zset, stream)
    - `rows` number, nullable, required: estimated rows (PostgreSQL/MySQL statistics), null when unknown
  - `nextCursor` string, nullable, required: Redis key listings: pass as cursor for the next page
  - `notices` string[], required
  - `transaction` 'idle' | 'open' | 'failed' | 'null', nullable, required: write mode: a transaction is still open (COMMIT or ROLLBACK it)

## Other responses

- `400`: Invalid request (code invalid_request)
- `401`: Missing or invalid session/token (code unauthorized)
- `403`: Not permitted (code forbidden); details.sessionRequired: the console needs a dashboard session
- `404`: Not found or not visible to the caller (code not_found)
- `409`: Conflicting state (code conflict): details.preparing (the console is connecting, retry after details.retryAfterSeconds), details.busy (a statement is running), details.ended (open a new session), details.reason console_limit
- `429`: Too many requests (code rate_limited); see Retry-After
- `501`: Not available on this server (code not_configured)
- `503`: The console did not answer in time (code provider_unavailable)

---

[API](https://skmtc.dev/hostingsurge/apis/hostingsurge-platform-api.md) · [All operations](https://skmtc.dev/hostingsurge/apis/hostingsurge-platform-api/llms.txt) · [OpenAPI document](https://skmtc.dev/hostingsurge/apis/hostingsurge-platform-api/revisions/4d08337cdff1?raw)
