---
updatedAt: 2026-10-25T15:46:36.000Z
agentTools:
  projectIndex: https://docs.superwise.ai/llms.txt
---

# Run Sql Query

Validate or execute an SQL SELECT statement against datasets.

- **sql** (str): Required. A SELECT statement where table names are dataset IDs.
- **validate_only** (bool): Optional. When True, validate without executing.

Validates or runs a SQL `SELECT` statement against datasets. Table names in the statement are dataset IDs.

## When to use it

Use it to read records from one or more datasets. Set `validate_only` to `true` to check a statement without running it, and `thumbnail_size` to embed image columns as base64 thumbnails.

## Required parameters

* `sql` (body): a SELECT SQL query to validate or execute.

Optional body fields: `validate_only`, `thumbnail_size`.

## Response

A successful call returns `200 OK` with `valid`, whether the statement is valid; `error`; and `data`, the result rows.

**Related:** [Query datasets in natural language](https://docs.superwise.ai/reference/run_nl_query), [Get a dataset](https://docs.superwise.ai/reference/get_dataset), [Get an image from a dataset](https://docs.superwise.ai/reference/get_media)

# OpenAPI definition

```json
{
  "openapi": "3.1.0",
  "paths": {
    "/v1/datasets/sql-query": {
      "post": {
        "tags": [
          "Dataset"
        ],
        "summary": "Run Sql Query",
        "description": "Validate or execute an SQL SELECT statement against datasets.\n\n- **sql** (str): Required. A SELECT statement where table names are dataset IDs.\n- **validate_only** (bool): Optional. When True, validate without executing.",
        "operationId": "run_sql_query",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SqlQueryRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SqlQueryResponse"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request"
          },
          "422": {
            "description": "Unprocessable Entity"
          }
        }
      }
    }
  },
  "info": {
    "title": "Superwise Main Entities",
    "description": "API reference",
    "version": "0.1.0"
  },
  "components": {
    "schemas": {
      "SqlQueryRequest": {
        "properties": {
          "sql": {
            "type": "string",
            "minLength": 1,
            "title": "Sql",
            "description": "A SELECT SQL query to validate or execute"
          },
          "validate_only": {
            "type": "boolean",
            "title": "Validate Only",
            "description": "When True, validate the SQL without executing it",
            "default": false
          },
          "thumbnail_size": {
            "anyOf": [
              {
                "type": "string",
                "enum": [
                  "small",
                  "medium",
                  "large"
                ]
              },
              {
                "type": "null"
              }
            ],
            "title": "Thumbnail Size",
            "description": "Fetch and base64-embed image columns at this thumbnail size"
          }
        },
        "type": "object",
        "required": [
          "sql"
        ],
        "title": "SqlQueryRequest"
      },
      "SqlQueryResponse": {
        "properties": {
          "valid": {
            "type": "boolean",
            "title": "Valid"
          },
          "error": {
            "type": "string",
            "title": "Error",
            "description": "Validation or execution error message, if any",
            "default": ""
          },
          "data": {
            "anyOf": [
              {
                "items": {
                  "additionalProperties": true,
                  "type": "object"
                },
                "type": "array"
              },
              {
                "type": "null"
              }
            ],
            "title": "Data",
            "description": "Query results. Null when not querying or validation fails"
          }
        },
        "type": "object",
        "required": [
          "valid"
        ],
        "title": "SqlQueryResponse"
      }
    },
    "securitySchemes": {
      "implicit": {
        "type": "oauth2",
        "flows": {
          "implicit": {
            "authorizationUrl": "https://authentication.superwise.ai/identity/resources/auth/v1/api-token",
            "scopes": {}
          }
        }
      }
    }
  },
  "security": [
    {
      "implicit": []
    }
  ],
  "servers": [
    {
      "url": "api.superwise.ai",
      "description": "Superwise Api Gateway"
    }
  ]
}
```