---
title: "Run SQL Query"
method: POST
path: "/v2/data/query/run"
tags: ["SQL API"]
---

# Run SQL Query

`POST /v2/data/query/run`

## Request

- Base URL: `https://api.cdp.coinbase.com/platform`
- URL: `https://api.cdp.coinbase.com/platform/v2/data/query/run`
- Auth: HTTP bearer

Run a read-only SQL query against indexed blockchain data including transactions, events, and decoded logs.

This endpoint provides direct SQL access to comprehensive blockchain data across supported networks.

Queries are executed against optimized data structures for high-performance analytics.

### Allowed Queries

  - Standard SQL syntax (CoinbaSeQL dialect, based on ClickHouse dialect)
  - Read-only queries (SELECT statements)
  - No DDL or DML operations
  - Query that follow limits (defined below)

### Supported Networks

  - Base Mainnet: `base`
  - Base Sepolia: `base_sepolia`
  - Solana Mainnet: `solana`
  - Hyperevm Mainnet: `hyperevm`

### Supported Tables

The below tables are supported for `base` and `base_sepolia` networks.

  | Table | Description |
  | --- | --- |
  | `<network>.events` | Decoded event logs with parameters, event signature, topics, and more. |
  | `<network>.transactions` | Transaction data including hash, block number, and gas usage. |
  | `<network>.blocks` | Block information. |
  | `<network>.encoded_logs` | Encoded log data for event logs that cannot be decoded by our event decoder (ex: log0 opcode). |
  | `<network>.decoded_user_operations` | Decoded user operations data including hash, block number, gas usage, builder codes, entrypoint version, and more. |
  | `<network>.transaction_attributions` | Information about the attributions of a transaction to a builder and associated builder codes. |

  Following the above, the valid tables on Base Mainnet are `base.events`, `base.transactions`, `base.blocks`, `base.encoded_logs`, `base.decoded_user_operations`, and `base.transaction_attributions`.

Separately, there is a limited set of tables supported for `solana` and `hyperevm` networks:

  | Table | Description |
  | --- | --- |
  | `solana.instructions` | Solana instruction call data including program ID, instruction data, and more. Currently supports just Token2022 and SPL Token programs. |
  | `hyperevm.events` | Hyperevm decoded event logs with parameters, event signature, topics, and more. Currently supports just B20 events. |

### Query Limits

  - Maximum result set: 50,000 rows
  - Maximum query length: 10,000 characters
  - Maximum on-disk data to read: 100GB
  - Maximum memory usage: 15GB
  - Query timeout: 30 seconds
  - Maximum JOINs: 12

### Query Caching

By default, each query result is returned from cache so long as the result is from an identical query and less than 750ms old. This freshness tolerance can be modified upwards, to a maximum of 900000ms (i.e. 900s, 15m).
This can be helpful for users who wish to reduce expensive calls to the SQL API by reusing cached results.

## Request body

- OnchainDataQuery: Request to execute a SQL query against indexed blockchain data.
  - `sql` string, required: SQL query to execute against the indexed blockchain data.
  - `cache` object: Enables control over how often queries need to be fully re-executed on the backing store. This can be useful in scenarios where API calls might be made frequently, API latency is critical, and some freshness lag (ex: 750ms, 2s, 5s) is tolerable. By default, each query result is returned from cache so long as the result is from an identical query and less than 500ms old. This freshness tolerance can be modified upwards, to a maximum of 900000ms (i.e. 900s, 15m).
    - `maxAgeMs` integer: The maximum tolerable staleness of the query result cache in milliseconds. If a previous execution result of an identical query is older than this age, the query will be re-executed. If the data is less than this age, the result will be returned from cache.

## Response `200`

Query run successfully.

- OnchainDataResult: Result of executing a SQL query.
  - `result` object[]: Query result as an array of objects representing rows.
  - `schema` object: Schema information for the query result. This is a derived schema from the query result, so types may not match the underlying table.
    - `columns` object[]: Column definitions.
      - `name` string: Column name.
      - `type` 'String' | 'UInt8' | 'UInt16' | 'UInt32' | 'UInt64' | 'UInt128' | 'UInt256' | 'Int8' | 'Int16' | 'Int32' | 'Int64' | 'Int128' | 'Int256' | 'Float32' | 'Float64' | 'Bool' | 'Date' | 'DateTime' | 'DateTime64' | 'UUID': Column data type (ClickHouse types).
  - `metadata` object: Metadata about query execution.
    - `cached` boolean: Whether the result was served from the query result cache.
    - `executionTimestamp` string, date-time: When the query result was executed against the backing store in RFC 3339 format.
    - `executionTimeMs` integer: Query execution time in milliseconds.
    - `rowCount` integer: Number of rows returned.

## Other responses

- `400`: The underlying SQL string is invalid.
- `401`: Unauthorized.
- `402`: A payment method is required to complete this operation.
- `408`: Query timeout.
- `429`: Rate limit exceeded.
- `499`: The client closed the connection before the server could send a response.
- `500`: Internal server error.
- `504`: The request timed out.

## Changes

- **2026-12-01** `06cb41a4fb57`: 8 warning
  - added the new `policy_not_applicable` enum value to the `errorType` response property for the response status `400`
  - added the new `policy_not_applicable` enum value to the `errorType` response property for the response status `401`
  - added the new `policy_not_applicable` enum value to the `errorType` response property for the response status `402`
  - added the new `policy_not_applicable` enum value to the `errorType` response property for the response status `408`
  - …4 more
- **2026-10-16** `ff3c1fdef902`: 8 warning
  - added the new `entity_not_configured_for_top_up` enum value to the `errorType` response property for the response status `400`
  - added the new `entity_not_configured_for_top_up` enum value to the `errorType` response property for the response status `401`
  - added the new `entity_not_configured_for_top_up` enum value to the `errorType` response property for the response status `402`
  - added the new `entity_not_configured_for_top_up` enum value to the `errorType` response property for the response status `408`
  - …4 more
- …earlier changes not shown

[Operation history](https://skmtc.dev/coinbase/apis/coinbase-developer-platform-apis/changes/v2/data/query/run/post.md)

---

[API](https://skmtc.dev/coinbase/apis/coinbase-developer-platform-apis.md) - [All operations](https://skmtc.dev/coinbase/apis/coinbase-developer-platform-apis/llms.txt) - [OpenAPI document](https://skmtc.dev/coinbase/apis/coinbase-developer-platform-apis/revisions/06cb41a4fb57?raw)
