run_sql

Runs a SQL query and returns the results as structured data

Recent Requests
Log in to see full request history
TimeStatusUser Agent
Retrieving recent requests…
LoadingLoading…

The /v2/run_sql endpoint executes SQL queries against your database and returns the results as structured data. This endpoint can be used to run SQL queries generated by the /v2/generate_sql endpoint or custom SQL queries you've written.

Basic Usage

// Request
{
  "projectId": 1,
  "sql": "SELECT * FROM \"olist_customers_dataset\" LIMIT 10"
}

// Response
{
  "id": "09d46224-0068-4ca3-bce4-f1fc85093eb6",
  "records": [
    {
      "customer_id": "00012a2ce6f8dcda20d059ce98491703",
      "customer_unique_id": "248ffe10d632bebe4f7267f1f44844c9",
      "customer_zip_code_prefix": "06273",
      "customer_city": "osasco",
      "customer_state": "SP"
    },
    {
      "customer_id": "000161a058600d5901f007fab4c27140",
      "customer_unique_id": "b0015e09bb4b6e47c52844fab5fb6638",
      "customer_zip_code_prefix": "35550",
      "customer_city": "itapecerica",
      "customer_state": "MG"
    },
    "... additional records ..."
  ],
  "columns": [
    {
      "name": "customer_id",
      "type": "VARCHAR"
    },
    {
      "name": "customer_unique_id",
      "type": "VARCHAR"
    },
    {
      "name": "customer_zip_code_prefix",
      "type": "VARCHAR"
    },
    {
      "name": "customer_city",
      "type": "VARCHAR"
    },
    {
      "name": "customer_state",
      "type": "VARCHAR"
    }
  ],
  "threadId": "503a8ca5-8171-43b5-b45b-86de2849467b",
  "totalRows": 10
}

Error Handling

{
  "id": "6fb82c31-a40d-4b8e-9e5f-c1d8a742db76",
  "code": "INVALID_SQL_ERROR",
  "error": "Table 'nonexistent_table' is not defined in the MDL manifest. In strict mode, all table references must correspond to MDL models."
}

Error codes may include:

  • INVALID_SQL_ERROR: The SQL could not be executed — invalid syntax, or a table/column that is not defined in the MDL manifest
  • NO_DEPLOYMENT_FOUND: No active deployment was found for the project

Workflow Example

  1. Generate SQL using the /v2/generate_sql endpoint
  2. Pass the generated SQL to /v2/run_sql to execute and get results
  3. Optionally use the same threadId in follow-up queries to maintain context
Body Params
integer
required
string
required

The Wren SQL query to execute.

string

Optional thread ID for conversation context.

integer
Defaults to 1000

Maximum number of rows to return.

Responses

Language
Credentials
Bearer
LoadingLoading…
Response
Click Try It! to start a request and see the response here! Or choose an example:
application/json