> ## Documentation Index
> Fetch the complete documentation index at: https://docs.rafftechnologies.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Run a query

> Run one statement against the database and get the result: SQL for PostgreSQL, MySQL, and ClickHouse, or one command for Valkey.

- Runs as the admin user, read-only unless you set `read_only: false`. A read-only run refuses writes.
- Returns at most `max_rows` rows (default 1,000, ceiling 5,000); `truncated` is `true` when more rows existed.
- A statement is stopped after 15 seconds.

Each row carries its values as strings in `cells`, with `nulls[i]` set when value `i` is SQL `NULL`.




## OpenAPI

````yaml POST /api/v1/databases/{database_id}/console
openapi: 3.0.3
info:
  title: Raff API
  description: >
    REST API for managing cloud infrastructure on Raff.


    ## Authentication

    Most endpoints require authentication via API key. Catalog endpoints under
    `/api/v1/public/` are open and require no authentication.


    ### API Key Authentication

    Include your API key in the `X-API-Key` header:
      ```
      curl -H "X-API-Key: YOUR_API_KEY" https://api.rafftechnologies.com/api/v1/vms
      ```

    ## Catalog

    Use the public catalog endpoints to discover available regions, OS
    templates, and pricing plans before creating resources:

    - `GET /api/v1/public/regions` — list available regions

    - `GET /api/v1/public/templates` — list OS templates (use the `id` as
    `template_id` when creating a VM)

    - `GET /api/v1/public/pricing/vm` — list VM pricing plans (use the `id` as
    `pricing_id` when creating a VM)

    - `GET /api/v1/public/pricing/volume` — volume storage pricing

    - `GET /api/v1/public/pricing/snapshot` — snapshot storage pricing

    - `GET /api/v1/public/pricing/backup` — backup storage pricing

    - `GET /api/v1/public/pricing/ip` — IP address pricing

    - `GET /api/v1/public/pricing/database` — managed database pricing (plans,
    high availability, read replicas, extra storage)

    - `GET /api/v1/public/pricing/kubernetes` — managed Kubernetes pricing
    (worker node plans, HA control plane, storage nodes)
  version: 1.0.0
  contact:
    name: Raff Technologies
    url: https://rafftechnologies.com
servers:
  - url: https://api.rafftechnologies.com
    description: Production
security:
  - ApiKeyAuth: []
tags:
  - name: Catalog
    description: >-
      Discover available regions, OS templates, and pricing plans. No
      authentication required.
  - name: Health
    description: Health check endpoints
  - name: Projects
    description: Organize resources into projects for billing and access control
  - name: Virtual Machines
  - name: Kubernetes
    description: >-
      Managed Kubernetes clusters — HA control planes, autoscaling node pools,
      kubeconfig access
  - name: Functions
    description: Deploy and manage serverless functions
  - name: Raff Apps
    description: >-
      Push-to-deploy web services, private services, workers, cron jobs, and
      one-off jobs on the Raff PaaS — with custom domains, environment
      variables, autoscaling, and per-second billing with spend caps
  - name: Managed Databases
    description: >-
      Fully managed PostgreSQL and Valkey databases with private VPC networking,
      automatic backups, and metrics
  - name: Networking
    description: >-
      Attach and detach VPCs, floating IPs, and security groups to VM network
      interfaces
  - name: Snapshots
    description: Point-in-time copies of VMs and volumes for quick rollback or cloning
  - name: Backups
    description: Scheduled and on-demand VM backups with restore capability
  - name: Backup Schedules
    description: Recurring daily or weekly backup schedules attached to a VM
  - name: SSH Keys
    description: Manage account-level SSH keys for VM provisioning
  - name: Members
    description: Account-level members — invite, list, update role, remove
  - name: Project Members
    description: Members of a specific project — same model as Members but project-scoped
  - name: Roles
    description: Custom roles bundling account or project permissions
  - name: Permissions
    description: List the catalog of permission strings used by roles
  - name: API Keys
    description: Create and manage API keys for programmatic access
  - name: Invitations
    description: Create and cancel email-based invitations to join the account or a project
paths:
  /api/v1/databases/{database_id}/console:
    post:
      tags:
        - Managed Databases
      summary: Run a query
      description: >
        Run one statement against the database and get the result: SQL for
        PostgreSQL, MySQL, and ClickHouse, or one command for Valkey.


        - Runs as the admin user, read-only unless you set `read_only: false`. A
        read-only run refuses writes.

        - Returns at most `max_rows` rows (default 1,000, ceiling 5,000);
        `truncated` is `true` when more rows existed.

        - A statement is stopped after 15 seconds.


        Each row carries its values as strings in `cells`, with `nulls[i]` set
        when value `i` is SQL `NULL`.
      operationId: runDatabaseQuery
      parameters:
        - $ref: '#/components/parameters/DatabaseIDPath'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RunDatabaseQueryRequest'
      responses:
        '200':
          description: Query result
          content:
            application/json:
              schema:
                allOf:
                  - type: object
                    properties:
                      success:
                        type: boolean
                  - $ref: '#/components/schemas/DatabaseQueryResult'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
components:
  parameters:
    DatabaseIDPath:
      name: database_id
      in: path
      required: true
      description: >-
        Database ID (UUID) or short id (the `database_id` field, e.g.
        `a1b2c3d4`)
      schema:
        type: string
  schemas:
    RunDatabaseQueryRequest:
      type: object
      required:
        - statement
      properties:
        statement:
          type: string
          description: One SQL statement, or one Valkey command
          example: SELECT id, email FROM users LIMIT 10;
        read_only:
          type: boolean
          default: true
          description: >-
            Refuse writes. Set `false` to run statements that change data or
            schema.
        max_rows:
          type: integer
          default: 1000
          description: Most rows to return (ceiling 5,000)
    DatabaseQueryResult:
      type: object
      properties:
        columns:
          type: array
          items:
            type: string
        rows:
          type: array
          items:
            $ref: '#/components/schemas/DatabaseRow'
        rows_affected:
          type: integer
          description: Rows changed by a write
        command:
          type: string
          description: Engine command tag, for example `SELECT 10` or `INSERT 0 1`
        notices:
          type: array
          items:
            type: string
        truncated:
          type: boolean
          description: More rows existed than `max_rows`
        duration_ms:
          type: number
    DatabaseRow:
      type: object
      properties:
        cells:
          type: array
          items:
            type: string
          description: Values in column order, as text
        nulls:
          type: array
          items:
            type: boolean
          description: '`true` where the value is SQL NULL'
    Error:
      type: object
      properties:
        error:
          type: string
        message:
          type: string
  responses:
    BadRequest:
      description: Invalid request parameters
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Unauthorized:
      description: Authentication required
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    NotFound:
      description: Resource not found
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-API-Key
      description: API key for authentication. Each key is bound to a specific account.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.