Skip to content

Run a read-only query

POST/v1/databases/{uid}/data/query

Runs one read-only statement against the database and returns the result as a grid. Nothing you run here can change data.

PostgreSQL

  • The statement runs in a READ ONLY transaction that is never committed, with default_transaction_read_only on. Writes (INSERT, UPDATE, DELETE, DDL and so on) fail with 400 and a message starting the data viewer is read-only:.
  • Only a single statement is accepted. A string with several statements is rejected by the server.
  • statement_timeout is 15 seconds and lock_timeout 3 seconds.
  • Values are returned in PostgreSQL text format, and column type is the PostgreSQL type name (for example int4, text, timestamptz).

MySQL

  • The session and transaction are read-only and multi-statement strings are not allowed. Writes fail with 400 and a message starting the data viewer is read-only:.
  • max_execution_time is 15 seconds and lock waits time out after 3 seconds.
  • Binary columns (BINARY, VARBINARY, BLOB types, BIT, GEOMETRY) are returned as 0x-prefixed hex. Column type is the lower-case MySQL type name.

Redis (Valkey)

  • sql holds one command line, split like redis-cli does: words separated by spaces, with "double" (supporting \n, \t, \" and \xHH) or 'single' quotes.
  • Only read-only commands are allowed: PING, ECHO, TIME, DBSIZE, INFO, LASTSAVE, TYPE, EXISTS, TTL, PTTL, EXPIRETIME, PEXPIRETIME, SCAN, RANDOMKEY, OBJECT ENCODING|FREQ|IDLETIME|REFCOUNT|HELP, MEMORY USAGE|STATS|HELP, GET, MGET, STRLEN, GETRANGE, SUBSTR, LCS, GETBIT, BITCOUNT, BITPOS, BITFIELD_RO, the read-only hash, list, set, sorted set and geo commands (HGET, HGETALL, HSCAN, LRANGE, LLEN, SMEMBERS, SSCAN, ZRANGE, ZSCORE, ZSCAN, GEOSEARCH and similar), XRANGE, XREVRANGE, XLEN, XPENDING, XINFO STREAM|GROUPS|CONSUMERS|HELP and SORT_RO. Anything else returns 400.
  • db selects the logical database, 0 to 15.
  • Replies are shaped into columns: INFO becomes section, key, value; HGETALL and HSCAN become field, value; WITHSCORES replies and ZSCAN become member, score; other arrays become #, value; single values become one value row. For SCAN-family commands, command is next cursor <n>. Nested arrays are returned as JSON strings. Column type is an empty string.
  • The whole reply is capped at 8 MB. Larger replies fail with 400; use a SCAN command or a narrower range.

Limits for all engines

  • sql can be at most 64 KiB.
  • At most 500 rows are returned. Results also stop once about 4 MiB of cell data has been read (SQL engines). When either cap is hit, truncated is true.
  • Each cell is cut at 8 KiB, ending with ….
  • null in rows means SQL NULL (or a nil Redis reply).
  • The database must be ready, and data browser calls share a small platform-wide pool of connections (409 when busy).

Requires the secrets read permission (owner, admin or developer role). Requests made with an mcp-scoped API key (AI assistants) return 403 unless command access is turned on in the workspace settings. The first 1000 characters of sql are recorded in the workspace audit log.

Authentication

Send your API key as Authorization: Bearer <token>. The request is scoped to the workspace in X-Workspace-Slug.

Path parameters

uidstringRequired

The database's uid.

Headers

X-Workspace-SlugstringRequired

Slug of the workspace the request acts on. You can also pass it as the workspace_slug query parameter.

Request body

sqlstringRequired

One SQL statement (PostgreSQL, MySQL) or one command line (Redis). Leading and trailing whitespace is trimmed.

max length 65536

dbinteger

Redis logical database to run the command against. Ignored for PostgreSQL and MySQL.

Default 0min 0 · max 15

Response

200

The statement's result.

successbooleanRequired

true when the request succeeded.

messagestringRequired

Human-readable status message.

dataobject
Show attributes
columnsarray of objectsRequired

Result columns, in order.

Show item attributes
namestringRequired

Column name.

typestringRequired

Type name reported by the engine (for example int4 in PostgreSQL or varchar in MySQL). Empty string for Redis and for unknown types.

rowsarray of array of string | nullssRequired

Result rows. Each row is an array of cells in column order. Every value is a string; null is SQL NULL.

row_countintegerRequired

Number of rows in rows.

truncatedbooleanRequired

true when more rows exist than were returned, because of the row cap, the page size or the response size cap.

commandstring

PostgreSQL's command tag (for example SELECT 2 or EXPLAIN). For MySQL, SELECT <n> when the statement returned columns. For Redis SCAN-family commands, next cursor <n>. Omitted when the result was truncated and otherwise when there is none.

duration_msintegerRequired

Time taken to run the statement and read the result, in milliseconds.

Errors

StatusMeaning
400The query was rejected or failed. Possible messages: sql is required (also sent for malformed JSON), query is too long, the data viewer is read-only: <reason>, the query was cancelled because it took too long, the command was cancelled because it took too long, <COMMAND> isn't available in the data viewer, which only runs read-only commands, unbalanced quotes in command, closing quote must be followed by a space, command is required, db must be between 0 and 15, the reply is larger than 8 MB, use a SCAN command or a narrower range, the database rejected the connection: <reason>, or the database's own error message (PostgreSQL errors include the detail in brackets when there is one).
401The API key is missing, invalid, expired or revoked.
403Your role cannot read secrets, or the request used an mcp-scoped API key and command access is turned off for the workspace.
404The resource does not exist or you cannot access it.
409The data browser cannot run right now. Possible messages: the database must be ready to browse its data, the data viewer is busy, try again in a moment, and couldn't reach the database, check that it's running and try again.

Errors use the standard error format.