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

# Run SQL against a SQL database

> Runs SQL against the database and returns the resulting rows — empty for statements that return none, such as DDL. Bind positional `?` placeholders with `params` rather than interpolating values into the SQL string.



## OpenAPI

````yaml /openapi/source/external/edge-compute/edge-compute.json post /storage/sqldbs/{id}/actions/query
openapi: 3.1.0
info:
  description: >-
    Edge Compute storage: KV namespaces and keys, SQL databases, and CloudFS
    filesystems.
  title: Edge Compute API
  contact: {}
  version: '1.0'
  x-endpoint-cost: light
  x-latency-category: responsive
servers:
  - url: https://api.telnyx.com/v2
    description: Production server
security:
  - bearerAuth: []
tags:
  - name: kv namespaces
    description: Manage KV storage namespaces
  - name: kv keys
    description: Read and write keys within a KV namespace
  - name: sql databases
    description: Manage SQL databases and run SQL against them
  - name: cloudfs filesystems
    description: >-
      Manage CloudFS filesystems — JuiceFS-compatible filesystems backed by
      Telnyx Cloud Storage
paths:
  /storage/sqldbs/{id}/actions/query:
    post:
      tags:
        - sql databases
      summary: Run SQL against a SQL database
      description: >-
        Runs SQL against the database and returns the resulting rows — empty for
        statements that return none, such as DDL. Bind positional `?`
        placeholders with `params` rather than interpolating values into the SQL
        string.
      operationId: QuerySqlDatabase
      parameters:
        - description: SQL database ID
          name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SqlDatabaseQueryRequest'
        description: The SQL to run, and any positional bind parameters
        required: true
      responses:
        '200':
          description: The SQL result
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SqlDatabaseQueryResponseWrapper'
        '400':
          description: Bad request — the request body is malformed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Errors'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Errors'
        '404':
          description: SQL database not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Errors'
        '409':
          description: >-
            Conflict — the database is not ready yet. This is transient; retry
            once it reaches `provision_ok`.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Errors'
        '413':
          description: The SQL body exceeds the maximum size (8 MiB)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Errors'
        '422':
          description: >-
            Validation error — an invalid `id`, empty `sql`, an unsupported bind
            parameter, the wrong number of bind parameters for the placeholders
            in `sql`, or a SQL error raised by the database. Also returned for a
            script over roughly 4 MiB, whose detail ends in `stream too large`:
            that transport ceiling is reached before the 8 MiB `413`, so ~4 MiB
            is the size to plan against
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Errors'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GenericErrorResponse'
      x-codeSamples:
        - lang: JavaScript
          source: |-
            import Telnyx from 'telnyx';

            const client = new Telnyx({
              apiKey: process.env['TELNYX_API_KEY'], // This is the default and can be omitted
            });

            const response = await client.storage.sqldbs.actions.query('id', {
              sql: 'SELECT * FROM users WHERE name = ?',
            });

            console.log(response.data);
        - lang: Python
          source: |
            import os
            from telnyx import Telnyx

            client = Telnyx(
                api_key=os.environ.get("TELNYX_API_KEY"),  # This is the default and can be omitted
            )
            response = client.storage.sqldbs.actions.query(
                id="id",
                sql="SELECT * FROM users WHERE name = ?",
            )
            print(response.data)
        - lang: Go
          source: "package main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\t\"github.com/team-telnyx/telnyx-go\"\n\t\"github.com/team-telnyx/telnyx-go/option\"\n)\n\nfunc main() {\n\tclient := telnyx.NewClient(\n\t\toption.WithAPIKey(\"My API Key\"),\n\t)\n\tresponse, err := client.Storage.Sqldbs.Actions.Query(\n\t\tcontext.TODO(),\n\t\t\"id\",\n\t\ttelnyx.StorageSqldbActionQueryParams{\n\t\t\tSQL: \"SELECT * FROM users WHERE name = ?\",\n\t\t},\n\t)\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf(\"%+v\\n\", response.Data)\n}\n"
        - lang: Java
          source: >-
            package com.telnyx.sdk.example;


            import com.telnyx.sdk.client.TelnyxClient;

            import com.telnyx.sdk.client.okhttp.TelnyxOkHttpClient;

            import
            com.telnyx.sdk.models.storage.sqldbs.actions.ActionQueryParams;


            public final class Main {
                private Main() {}

                public static void main(String[] args) {
                    TelnyxClient client = TelnyxOkHttpClient.fromEnv();

                    ActionQueryParams params = ActionQueryParams.builder()
                        .sql("SELECT * FROM users WHERE name = ?")
                        .build();
                    var response = client.storage().sqldbs().actions().query("id", params);
                }
            }
        - lang: Ruby
          source: >-
            require "telnyx"


            telnyx = Telnyx::Client.new(api_key: "My API Key")


            response = telnyx.storage.sqldbs.actions.query("id", sql: "SELECT *
            FROM users WHERE name = ?")


            puts(response)
        - lang: PHP
          source: >-
            <?php


            require_once dirname(__DIR__) . '/vendor/autoload.php';


            use Telnyx\Client;

            use Telnyx\Core\Exceptions\APIException;


            $client = new Client(apiKey: getenv('TELNYX_API_KEY') ?: 'My API
            Key');


            try {
              $response = $client->storage->sqldbs->actions->query(
                'id',
                sql: 'SELECT * FROM users WHERE name = ?',
              );

              var_dump($response);
            } catch (APIException $e) {
              echo $e->getMessage();
            }
        - lang: CLI
          source: |-
            telnyx storage:sqldbs:actions query \
              --api-key 'My API Key' \
              --id id \
              --sql 'SELECT * FROM users WHERE name = ?'
components:
  schemas:
    SqlDatabaseQueryRequest:
      type: object
      properties:
        sql:
          type: string
          description: >-
            The SQL to run. Use positional `?` placeholders and supply the
            values in `params` rather than interpolating them into this string.
          example: SELECT * FROM users WHERE name = ?
        params:
          type: array
          description: >-
            Positional bind parameters, in placeholder order. Each value is a
            string, a number, a boolean, or null; booleans are cast to `1`/`0`.
            The count must match the number of `?` placeholders exactly — a
            mismatch is rejected with 422 rather than binding null for the ones
            you left out. (Not enforced for multi-statement scripts or named
            parameters, where the placeholder count is not the number bound.)
          items:
            type:
              - string
              - number
              - boolean
              - 'null'
          example:
            - alice
      required:
        - sql
    SqlDatabaseQueryResponseWrapper:
      type: object
      properties:
        data:
          $ref: '#/components/schemas/SqlDatabaseQueryResult'
    Errors:
      type: object
      properties:
        errors:
          type: array
          items:
            $ref: '#/components/schemas/Error'
    GenericErrorResponse:
      type: object
      properties:
        errors:
          type: array
          items:
            $ref: '#/components/schemas/Error'
    SqlDatabaseQueryResult:
      type: object
      properties:
        results:
          type: array
          description: >-
            The result rows, each a map of column name to value. Empty for
            statements that return no rows.
          items:
            type: object
            additionalProperties: true
        success:
          type: boolean
          example: true
        count:
          type: integer
          description: Number of rows returned.
          example: 1
        duration:
          type: number
          description: Wall-clock duration of the request, in milliseconds.
          example: 2.5
        meta:
          $ref: '#/components/schemas/SqlDatabaseQueryResultMeta'
    Error:
      type: object
      properties:
        code:
          type: string
          example: '10005'
        detail:
          type: string
          example: The requested function does not exist or you don't have access to it
        meta:
          $ref: '#/components/schemas/ErrorMeta'
        source:
          $ref: '#/components/schemas/ErrorSource'
        title:
          type: string
          example: Function not found
    SqlDatabaseQueryResultMeta:
      type: object
      properties:
        duration:
          type: number
          description: Wall-clock duration of the statement, in milliseconds.
          example: 1.2
        rows_read:
          type: integer
          example: 3
        rows_written:
          type: integer
          example: 0
        last_row_id:
          type: integer
          description: Rowid of the last inserted row, when applicable.
          example: 0
        changes:
          type: integer
          description: Number of rows added, changed, or removed by the statement.
          example: 0
    ErrorMeta:
      type: object
      properties:
        url:
          type: string
          example: https://docs.telnyx.com/api/errors/10005
    ErrorSource:
      type: object
      properties:
        parameter:
          type: string
          example: id
        pointer:
          type: string
          example: /id
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````