---
title: Raw D1 Database query
---

[Skip to content](#_top)

[API Reference](https://developers.cloudflare.com/api/go)

[D1](https://developers.cloudflare.com/api/go/resources/d1)

[Database](https://developers.cloudflare.com/api/go/resources/d1/subresources/database)

Copy Markdown

Open in **Claude**Open in **ChatGPT**Open in **Cursor**

---

**Copy Markdown****View as Markdown**

# Raw D1 Database query

client.D1.Database.Raw(ctx, databaseID, params) (\*SinglePage\[[DatabaseRawResponse](<https://developers.cloudflare.com/api/go/resources/d1#(resource)%20d1.database%20%3E%20(model)%20DatabaseRawResponse%20%3E%20(schema)>)], error)

POST/accounts/{account\_id}/d1/database/{database\_id}/raw

Execute a SQL query against a D1 database and return result rows as arrays rather than objects. This is a performance-optimized version of the /query endpoint.

##### Security

<details>

<summary>API Token</summary>



The preferred authorization scheme for interacting with the Cloudflare API. <a href="https://developers.cloudflare.com/fundamentals/api/get-started/create-token/">Create a token</a>.

**Example:**<code>Authorization: Bearer Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY</code>

</details>

<details>

<summary>API Email + API Key</summary>



The previous authorization scheme for interacting with the Cloudflare API, used in conjunction with a Global API key.

**Example:**<code>X-Auth-Email: user@example.com</code>

The previous authorization scheme for interacting with the Cloudflare API. When possible, use API tokens instead of Global API keys.

**Example:**<code>X-Auth-Key: 144c9defac04969c7bfad8efaa8ea194</code>

</details>

##### Accepted Permissions (at least one required)

`D1 Read``D1 Write`

##### ParametersExpand Collapse

databaseID string

D1 database identifier (UUID).

[Link to this property](<#(resource)%20d1.database%20%3E%20(method)%20raw%20%3E%20(params)%20default%20%3E%20(param)%20database_id%20%3E%20(schema)>)

<details>

<summary>

params DatabaseRawParams

</summary>

AccountID param.Field\[string]

Path param: Account identifier tag.

maxLength32

<a href="#(resource)%20d1.database%20%3E%20(method)%20raw%20%3E%20(params)%200%20%3E%20(param)%20account_id">Link to this property</a>

Sql param.Field\[string]

Body param: Your SQL query. Supports multiple statements, joined by semicolons, which will be executed as a batch.

<a href="#(resource)%20d1.database%20%3E%20(method)%20raw%20%3E%20(params)%200%20%3E%20(param)%20sql">Link to this property</a>

Params param.Field\[\[]string]Optional

Body param

<a href="#(resource)%20d1.database%20%3E%20(method)%20raw%20%3E%20(params)%200%20%3E%20(param)%20params">Link to this property</a>

</details>

[Link to this property](<#(resource)%20d1.database%20%3E%20(method)%20raw%20%3E%20(params)%200>)

##### ReturnsExpand Collapse

<details>

<summary>

type DatabaseRawResponse struct{…}

</summary>

<details>

<summary>

Meta DatabaseRawResponseMetaOptional

</summary>

ChangedDB boolOptional

Denotes if the database has been altered in some way, like deleting rows.

<a href="#(resource)%20d1.database%20%3E%20(model)%20DatabaseRawResponse%20%3E%20(schema)%20%3E%20(property)%20meta%20%3E%20(property)%20changed_db">Link to this property</a>

Changes float64Optional

Rough indication of how many rows were modified by the query, as provided by SQLite’s <code>sqlite3_total_changes()</code>.

<a href="#(resource)%20d1.database%20%3E%20(model)%20DatabaseRawResponse%20%3E%20(schema)%20%3E%20(property)%20meta%20%3E%20(property)%20changes">Link to this property</a>

Duration float64Optional

The duration of the SQL query execution inside the database. Does not include any network communication.

<a href="#(resource)%20d1.database%20%3E%20(model)%20DatabaseRawResponse%20%3E%20(schema)%20%3E%20(property)%20meta%20%3E%20(property)%20duration">Link to this property</a>

LastRowID float64Optional

The row ID of the last inserted row in a table with an <code>INTEGER PRIMARY KEY</code> as provided by SQLite. Tables created with <code>WITHOUT ROWID</code> do not populate this.

<a href="#(resource)%20d1.database%20%3E%20(model)%20DatabaseRawResponse%20%3E%20(schema)%20%3E%20(property)%20meta%20%3E%20(property)%20last_row_id">Link to this property</a>

RowsRead float64Optional

Number of rows read during the SQL query execution, including indices (not all rows are necessarily returned).

<a href="#(resource)%20d1.database%20%3E%20(model)%20DatabaseRawResponse%20%3E%20(schema)%20%3E%20(property)%20meta%20%3E%20(property)%20rows_read">Link to this property</a>

RowsWritten float64Optional

Number of rows written during the SQL query execution, including indices.

<a href="#(resource)%20d1.database%20%3E%20(model)%20DatabaseRawResponse%20%3E%20(schema)%20%3E%20(property)%20meta%20%3E%20(property)%20rows_written">Link to this property</a>

ServedByColo stringOptional

The three letters airport code of the colo that handled the query.

<a href="#(resource)%20d1.database%20%3E%20(model)%20DatabaseRawResponse%20%3E%20(schema)%20%3E%20(property)%20meta%20%3E%20(property)%20served_by_colo">Link to this property</a>

ServedByPrimary boolOptional

Denotes if the query has been handled by the database primary instance.

<a href="#(resource)%20d1.database%20%3E%20(model)%20DatabaseRawResponse%20%3E%20(schema)%20%3E%20(property)%20meta%20%3E%20(property)%20served_by_primary">Link to this property</a>

<details>

<summary>

ServedByRegion DatabaseRawResponseMetaServedByRegionOptional

Region location hint of the database instance that handled the query.

</summary>

One of the following:

const DatabaseRawResponseMetaServedByRegionWnam DatabaseRawResponseMetaServedByRegion = "WNAM"

<a href="#(resource)%20d1.database%20%3E%20(model)%20DatabaseRawResponse%20%3E%20(schema)%20%3E%20(property)%20meta%20%3E%20(property)%20served_by_region%20%3E%20(member)%200">Link to this property</a>

const DatabaseRawResponseMetaServedByRegionEnam DatabaseRawResponseMetaServedByRegion = "ENAM"

<a href="#(resource)%20d1.database%20%3E%20(model)%20DatabaseRawResponse%20%3E%20(schema)%20%3E%20(property)%20meta%20%3E%20(property)%20served_by_region%20%3E%20(member)%201">Link to this property</a>

const DatabaseRawResponseMetaServedByRegionWeur DatabaseRawResponseMetaServedByRegion = "WEUR"

<a href="#(resource)%20d1.database%20%3E%20(model)%20DatabaseRawResponse%20%3E%20(schema)%20%3E%20(property)%20meta%20%3E%20(property)%20served_by_region%20%3E%20(member)%202">Link to this property</a>

const DatabaseRawResponseMetaServedByRegionEeur DatabaseRawResponseMetaServedByRegion = "EEUR"

<a href="#(resource)%20d1.database%20%3E%20(model)%20DatabaseRawResponse%20%3E%20(schema)%20%3E%20(property)%20meta%20%3E%20(property)%20served_by_region%20%3E%20(member)%203">Link to this property</a>

const DatabaseRawResponseMetaServedByRegionApac DatabaseRawResponseMetaServedByRegion = "APAC"

<a href="#(resource)%20d1.database%20%3E%20(model)%20DatabaseRawResponse%20%3E%20(schema)%20%3E%20(property)%20meta%20%3E%20(property)%20served_by_region%20%3E%20(member)%204">Link to this property</a>

const DatabaseRawResponseMetaServedByRegionOc DatabaseRawResponseMetaServedByRegion = "OC"

<a href="#(resource)%20d1.database%20%3E%20(model)%20DatabaseRawResponse%20%3E%20(schema)%20%3E%20(property)%20meta%20%3E%20(property)%20served_by_region%20%3E%20(member)%205">Link to this property</a>

</details>

<a href="#(resource)%20d1.database%20%3E%20(model)%20DatabaseRawResponse%20%3E%20(schema)%20%3E%20(property)%20meta%20%3E%20(property)%20served_by_region">Link to this property</a>

SizeAfter float64Optional

Size of the database after the query committed, in bytes.

<a href="#(resource)%20d1.database%20%3E%20(model)%20DatabaseRawResponse%20%3E%20(schema)%20%3E%20(property)%20meta%20%3E%20(property)%20size_after">Link to this property</a>

<details>

<summary>

Timings DatabaseRawResponseMetaTimingsOptional

Various durations for the query.

</summary>

SqlDurationMs float64Optional

The duration of the SQL query execution inside the database. Does not include any network communication.

<a href="#(resource)%20d1.database%20%3E%20(model)%20DatabaseRawResponse%20%3E%20(schema)%20%3E%20(property)%20meta%20%3E%20(property)%20timings%20%3E%20(property)%20sql_duration_ms">Link to this property</a>

</details>

<a href="#(resource)%20d1.database%20%3E%20(model)%20DatabaseRawResponse%20%3E%20(schema)%20%3E%20(property)%20meta%20%3E%20(property)%20timings">Link to this property</a>

</details>

<a href="#(resource)%20d1.database%20%3E%20(model)%20DatabaseRawResponse%20%3E%20(schema)%20%3E%20(property)%20meta">Link to this property</a>

<details>

<summary>

Results DatabaseRawResponseResultsOptional

</summary>

Columns \[]stringOptional

<a href="#(resource)%20d1.database%20%3E%20(model)%20DatabaseRawResponse%20%3E%20(schema)%20%3E%20(property)%20results%20%3E%20(property)%20columns">Link to this property</a>

<details>

<summary>

Rows \[]\[]unknownOptional

</summary>

One of the following:

unknown

<a href="#(resource)%20d1.database%20%3E%20(model)%20DatabaseRawResponse%20%3E%20(schema)%20%3E%20(property)%20results%20%3E%20(property)%20rows%20%3E%20(items)%20%3E%20(items)%20%3E%20(variant)%202">Link to this property</a>

</details>

<a href="#(resource)%20d1.database%20%3E%20(model)%20DatabaseRawResponse%20%3E%20(schema)%20%3E%20(property)%20results%20%3E%20(property)%20rows">Link to this property</a>

</details>

<a href="#(resource)%20d1.database%20%3E%20(model)%20DatabaseRawResponse%20%3E%20(schema)%20%3E%20(property)%20results">Link to this property</a>

Success boolOptional

<a href="#(resource)%20d1.database%20%3E%20(model)%20DatabaseRawResponse%20%3E%20(schema)%20%3E%20(property)%20success">Link to this property</a>

</details>

[Link to this property](<#(resource)%20d1.database%20%3E%20(model)%20DatabaseRawResponse%20%3E%20(schema)>)

### Raw D1 Database query

Go

HTTPTypeScriptPythonGoTerraform

```
package main

import (
  "context"
  "fmt"

  "github.com/cloudflare/cloudflare-go"
  "github.com/cloudflare/cloudflare-go/d1"
  "github.com/cloudflare/cloudflare-go/option"
)

func main() {
  client := cloudflare.NewClient(
    option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"),
  )
  page, err := client.D1.Database.Raw(
    context.TODO(),
    "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    d1.DatabaseRawParams{
      AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
      Body: d1.DatabaseRawParamsBodyD1SingleQuery{
        Sql: cloudflare.F("SELECT * FROM myTable WHERE field = ? OR field = ?;"),
      },
    },
  )
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", page)
}
```

200 example

```
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "result": [
    {
      "meta": {
        "changed_db": true,
        "changes": 0,
        "duration": 0,
        "last_row_id": 0,
        "rows_read": 0,
        "rows_written": 0,
        "served_by_colo": "LHR",
        "served_by_primary": true,
        "served_by_region": "EEUR",
        "size_after": 0,
        "timings": {
          "sql_duration_ms": 0
        }
      },
      "results": {
        "columns": [
          "string"
        ],
        "rows": [
          [
            0
          ]
        ]
      },
      "success": true
    }
  ],
  "success": true
}
```

##### Returns Examples

200 example

```
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "result": [
    {
      "meta": {
        "changed_db": true,
        "changes": 0,
        "duration": 0,
        "last_row_id": 0,
        "rows_read": 0,
        "rows_written": 0,
        "served_by_colo": "LHR",
        "served_by_primary": true,
        "served_by_region": "EEUR",
        "size_after": 0,
        "timings": {
          "sql_duration_ms": 0
        }
      },
      "results": {
        "columns": [
          "string"
        ],
        "rows": [
          [
            0
          ]
        ]
      },
      "success": true
    }
  ],
  "success": true
}
```