Query a database

SDK platic.tools.databases.query()

Run a read-only SELECT with the same rules as the agent: the connection's time limit, paginated results, and hidden tables and columns excluded. Use it to check results before assigning the database to an agent.

Example

await platic.tools.databases.query("db_123", { sql: "SELECT id, total FROM orders ORDER BY id" });

Path parameters

ParameterTypeDescriptionRequired
databaseIdstringThe id of the connection✓

Request body

FieldTypeDescriptionRequired
sqlstringA single SELECT, up to 10,000 charactersOn the first page
pageSizenumberRows per page, from 1 to 200. Defaults to the connection's pageSize. Only on the first page—
cursorstringThe nextCursor of the previous page, exactly as it arrivedOn the following pages

Send sql for the first page and only cursor for subsequent pages.

The first page carries the query:

{
  "sql": "SELECT id, total, status FROM orders ORDER BY id",
  "pageSize": 2
}

The following ones carry only the cursor of the previous page:

{
  "cursor": "eyJ2IjoxLCJvIjoyfQ.k3Jx9mQ2"
}

Response

200 OK.

{
  "status": "success",
  "data": {
    "columns": ["id", "total", "status"],
    "rows": [
      [1001, 1250.5, "delivered"],
      [1002, 380, "in transit"]
    ],
    "rowCount": 2,
    "hasMore": true,
    "nextCursor": "eyJ2IjoxLCJvIjoyfQ.k3Jx9mQ2"
  }
}
FieldTypeDescription
columnsstring[]The columns of the SELECT, in order
rowsarray[]Each row is a list of values, in the order of columns. A value longer than 1,000 characters arrives cut
rowCountnumberHow many rows this page has
hasMorebooleanWhether there are more rows
nextCursorstringOnly with hasMore: send it as cursor for the next page. It lasts 30 minutes
notesstring[]Notices, for example that the page was cut so it would not exceed the maximum size

Errors

Statusdetails.codeWhen it happens
400INVALID_REQUESTsql and cursor are both missing, both are present, or a value is not accepted
400SQL_READ_ONLYIt is not a SELECT, it writes something, or it uses SELECT … INTO or locks
400SQL_SINGLE_STATEMENTIt has more than one statement
400SQL_TABLE_NOT_AVAILABLEIt uses a hidden or system table
400SQL_COLUMNS_REQUIREDIt uses * (or the whole row) on a table with hidden columns: name the columns
400SQL_COLUMN_NOT_AVAILABLEIt uses a hidden column
400SQL_FUNCTION_NOT_ALLOWEDIt uses a function that is not allowed
400SQL_NOT_SUPPORTEDThe query could not be parsed or uses syntax that is not supported
400CURSOR_INVALID or CURSOR_EXPIREDThe cursor is not from this connection, was tampered with, or more than 30 minutes passed. Run the query again
403FORBIDDEN or INSUFFICIENT_SCOPEThe person behind the token does not have access to Integrations, or the token does not have write permission
404NOT_FOUNDThere is no connection with that id in the workspace
409DB_TIMEOUTThe query went over the time limit and was cancelled. Make it more specific
409DB_ERROR, DB_PERMISSION_DENIED, and the other DB_*The database rejected the query, for example because of a column that does not exist, or did not respond. message says what happened
503TRANSPORT_UNAVAILABLEDatabase queries are not available right now. Try again

Notes

  • Querying does not write anything to the database: it is safe to repeat.
  • Neither the query nor the rows are kept in the API logs.