---
title: "Execute a tabular DDSQL query"
method: POST
path: "/api/v2/ddsql/query/tabular"
tags: ["DDSQL"]
---

# Execute a tabular DDSQL query

`POST /api/v2/ddsql/query/tabular`

## Request

- Base URL: `https://api.datadoghq.com`
- URL: `https://api.datadoghq.com/api/v2/ddsql/query/tabular`
- Auth: one of:
  - API key in header `DD-API-KEY` and API key in header `DD-APPLICATION-KEY`
  - OAuth 2
    - Authorization code: `/oauth2/v1/authorize`
    - Token URL: `/oauth2/v1/token` scopes: `timeseries_query`
- TypeScript: <https://skmtc.dev/datadog/apis/datadog-api-v2-collection/docs/api/v2/ddsql/query/tabular/post.ts> (a function with typed inputs; its response is checked against the schema)

Submit a DDSQL statement and return either a `running` state with an opaque `query_id`
for the client to poll, or a `completed` state with the column-major result set inlined
when the query finishes quickly enough to be served synchronously.

For a scoped application key, include `timeseries_query` in its scopes.
A query that does not read a data source, such as `SELECT 1`, requires no additional
data-source permissions. Queries that read data sources also require the user or
service account that owns the application key to have the corresponding data access
permissions through their roles. The `timeseries_query` permission does not grant
access to the underlying data sources.

## Request body

- DdsqlTabularQueryRequest: Wrapper for a DDSQL tabular query execution request.
  - `data` DdsqlTabularQueryRequestData, required: JSON:API resource object for a DDSQL tabular query execution request.
    - `attributes` DdsqlTabularQueryRequestAttributes, required: Attributes describing the DDSQL query to execute.
      - `query` string, required: The DDSQL statement to execute. DDSQL is Datadog's SQL dialect, which is a subset of PostgreSQL, scoped to Datadog data sources.
      - `row_limit` integer: Cap on the number of rows returned. Defaults to 5,000 when omitted. Must be between 1 and 10,000 inclusive; values outside this range are rejected with 400.
      - `time` DdsqlTabularQueryTimeWindow, required: Time window scoping the underlying data sources, expressed in Unix milliseconds since the epoch. Inclusive on `from_timestamp`, exclusive on `to_timestamp`. Results from static tables (for example, `dd.hosts`) are not affected by the time window, but the field must still be provided.
        - `from_timestamp` integer, required: Start of the query window (inclusive), in Unix milliseconds since the epoch.
        - `to_timestamp` integer, required: End of the query window (exclusive), in Unix milliseconds since the epoch.
    - `type` 'ddsql_query_request', required: JSON:API resource type for a DDSQL tabular query request.

## Response `200`

OK

- DdsqlTabularQueryResponse: Response envelope for both the execute and fetch DDSQL tabular query endpoints. Carries the JSON:API primary resource and a top-level `meta` block with request-scoped observability handles.
  - `data` DdsqlTabularQueryResponseData, required: JSON:API resource object for a DDSQL tabular query response.
    - `attributes` DdsqlTabularQueryResponseAttributes, required: Attributes of a DDSQL tabular query response. `query_id` is set when `state` is `running`; `columns` is set when `state` is `completed`.
      - `columns` DdsqlTabularQueryColumn[]: Column-major result set. Each element carries one column's name, type, and values, with one value per row of the result. Set when `state` is `completed`.
        - `name` string, required: Name of the column as projected by the SQL statement.
        - `type` string, required: DDSQL data type of the column's values, for example `VARCHAR`, `BIGINT`, `DECIMAL`, `BOOLEAN`, `TIMESTAMP`, `JSON`, or an array variant such as `VARCHAR[]`. See the [DDSQL data-types reference](https://docs.datadoghq.com/ddsql_reference/#data-types) for the full, up-to-date list.
        - `values` unknown[], required: Column values in row order, one entry per result row. The element type follows the column's `type`. The following serialization rules should be taken into account: - `BIGINT` values are encoded as JSON numbers in the signed 64-bit integer range. - `DECIMAL` values are encoded as JSON numbers with 64-bit double precision. - `TIMESTAMP` and `DATE` values are encoded as Unix-millisecond integers; a `DATE` resolves to midnight UTC. - `JSON` values are returned as a JSON-encoded string. `null` is allowed for any column type where a value is missing.
          - unknown
      - `query_id` string: Opaque token to pass to the fetch endpoint to poll for results. Set when `state` is `running` and absent when `state` is `completed`.
      - `state` 'running' | 'completed', required: Lifecycle state of a DDSQL tabular query response. `running` means the query is still executing and the client should poll the fetch endpoint with the returned `query_id`. `completed` means the result set is inlined in `columns` and no further polling is required.
      - `warnings` string[]: Non-fatal messages emitted by the query engine while serving this response.
    - `id` string, required: Stable identifier for the query response resource.
    - `type` 'ddsql_query_response', required: JSON:API resource type for a DDSQL tabular query response.
  - `meta` DdsqlTabularQueryResponseMeta, required: Top-level JSON:API meta block accompanying every DDSQL tabular query response. Carries standard observability handles for client-side correlation.
    - `elapsed` integer, required: Server-side time spent serving this request, in milliseconds.
    - `request_id` string, required: Echo of the `DD-Request-ID` header assigned by Datadog's edge to this request, for support correlation.

## Other responses

- `400`: Bad Request
- `403`: Forbidden
- `429`: Too many requests
- `500`: Internal Server Error

---

[API](https://skmtc.dev/datadog/apis/datadog-api-v2-collection.md) - [All operations](https://skmtc.dev/datadog/apis/datadog-api-v2-collection/llms.txt) - [OpenAPI document](https://skmtc.dev/datadog/apis/datadog-api-v2-collection/revisions/3f70db624329?raw)
