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

# Execute SQL query

> Allows execution of arbitrary SQL queries against the Sample database. Supports parameterized queries with complex data types including arrays, objects, and nested structures. Examples: arrays can be used with ANY/ALL operators, objects as structs for complex filtering.



## OpenAPI

````yaml https://app.stainless.com/api/spec/documented/samplehc/openapi.documented.yml post /api/v2/database/sql
openapi: 3.0.3
info:
  title: Sample Healthcare API
  description: API for Sample Healthcare
  version: 1.0.0
servers: []
security: []
paths:
  /api/v2/database/sql:
    post:
      tags:
        - Database
      summary: Execute SQL query
      description: >-
        Allows execution of arbitrary SQL queries against the Sample database.
        Supports parameterized queries with complex data types including arrays,
        objects, and nested structures. Examples: arrays can be used with
        ANY/ALL operators, objects as structs for complex filtering.
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                query:
                  type: string
                  description: The SQL query to execute.
                params:
                  type: array
                  items:
                    anyOf:
                      - type: string
                      - type: number
                      - type: boolean
                      - enum:
                          - 'null'
                        nullable: true
                      - type: array
                        items: {}
                      - type: object
                        additionalProperties: {}
                  description: >-
                    An array of parameters to be used in the SQL query. Supports
                    primitive types (string, number, boolean, null), arrays, and
                    objects. Use placeholders like $1, $2, etc. in the query
                    string. Examples: ["hello", 123, [1,2,3], {"name": "John",
                    "age": 30}]
              required:
                - query
              additionalProperties: false
        required: true
      responses:
        '200':
          description: The result of the SQL query execution.
          content:
            application/json:
              schema:
                type: object
                properties:
                  rows:
                    anyOf:
                      - type: array
                        items:
                          type: object
                          properties: {}
                          additionalProperties: true
                      - type: array
                        items:
                          type: array
                    description: >-
                      An array of results from the query. Each item is an object
                      with the column names as keys.
                required:
                  - rows
                additionalProperties: false
        '400':
          description: >-
            Bad Request: The SQL query, parameters, or request format is
            invalid.
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    description: A message describing the error.
                required:
                  - error
                additionalProperties: false
        '500':
          description: >-
            Internal Server Error: An unexpected error occurred while executing
            the SQL query.
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    description: A message describing the error.
                required:
                  - error
                additionalProperties: false
      x-codeSamples:
        - lang: Python
          source: |-
            import os
            from samplehc import SampleHealthcare

            client = SampleHealthcare(
                api_key=os.environ.get("SAMPLEHC_API_KEY"),  # This is the default and can be omitted
            )
            response = client.v2.database.execute_sql(
                query="query",
            )
            print(response.rows)

````