> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://ocient.ferndocs.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://ocient.ferndocs.com/_mcp/server.

# Execute SQL statement (GET method)

GET /v1/execute

Alternative GET method for executing SQL statements. Parameters are passed
as URL query parameters. Does not support the params field.

The database can be specified in the query parameters, or defaults to the database
from the authentication token or system settings.

This method is most suitable for simple, read-only queries where the statement
can be safely included in a URL. For complex queries or those with parameters,
use the POST method instead.

### Example

```
GET /v1/execute?statement=SELECT%20*%20FROM%20customers%20LIMIT%2010&database=retail&format=collection
```

### Limitations

- URL length restrictions may limit the complexity of queries
- No support for parameterized queries
- Less secure for queries containing sensitive data


Reference: https://ocient.ferndocs.com/api-reference/query-execution/execute-get

## Authentication

- `Authorization` header (bearer token, required) — Access token obtained from the login endpoint
- `Authorization` header (basic auth, required) — HTTP Basic authentication with username and password

## Request

### Query parameters

- `statement` (string, required) — SQL statement to execute. The statement must be URL-encoded. **Example**: `SELECT * FROM customers LIMIT 10`
- `database` (string, optional) — Target database name to execute the query against. If not specified, the database from authentication will be used.
- `format` (enum, optional, default: array) — Response format: * array - Returns schema and data as arrays (more efficient for large datasets) * collection - Returns data as JSON objects (more convenient for client processing)
  - Allowed values: `array`, `collection`
- `fetch_size` (integer, optional, default: 100) — Number of rows to return in each chunk for streaming responses. - For interactive applications: Use smaller values (100-1000) - For batch processing: Use larger values (5000-10000)

### Headers

- `Accept-Encoding` (string, optional) — Supported compression algorithms for responses. Multiple algorithms can be specified as a comma-separated list. Common values include 'gzip', 'deflate', 'br' (Brotli), or combinations like 'gzip, br'. Note that for large result sets, compression may produce suboptimal results. Without compression the result sets can be chunks of rows and processed in a streaming fashion. With compression the entire result set must be compressed before it is returned to the client. Thus the entire result set will be decompressed on the client before any rows can be processed
- `Accept` (enum, optional, default: application/json) — Supported response media types. Note that regardless of the Accept header, large queries results will always be returned via chunked encoding. Also see the note about compression in the AcceptEncoding section.
  - Allowed values: `application/json`, `application/stream+json`, `application/parquet`
- `Preferred-Encoding` (enum, optional) — Indicates the preferred encoding type from those specified in Accept-Encoding. This header provides fine-grained control when Accept-Encoding contains multiple values, allowing the client to explicitly specify which encoding is preferred for this specific request.
  - Allowed values: `gzip`, `br`
- `Preferred-Compression-Level` (integer, optional) — Specifies the desired compression level for the selected encoding algorithm. Values typically range from 1 (fastest, least compression) to 9 (slowest, maximum compression). The exact behavior depends on the specific compression algorithm being used.

## Response

### 200

Query executed successfully

- `Query Execution_execute_get_Response_200`
  - ArrayExecuteResponse
  - CollectionExecuteResponse

## Errors

### 401 Unauthorized Error

Unauthorized

- `status` (Status, required)

### 404 Not Found Error

Object not found

- `status` (Status, required)

### 500 Internal Server Error

Server Error

- `status` (Status, required)

## Types

### ArrayExecuteResponse

- `query_id` (string, required, nullable) — Unique identifier for the query.
- `status` (Status, required)
- `schema` (list of ArrayExecuteResponseSchemaItems, required) — Array of column metadata objects describing the structure of the result set. Each object contains the column name and data type.
- `data` (list of list of any, required) — Two-dimensional array containing the query results. The outer array represents rows, and each inner array contains column values in the same order as defined in the schema.

### CollectionExecuteResponse

- `query_id` (string, required, nullable) — Unique identifier for the query.
- `status` (Status, required)
- `data` (list of map from string to any, required) — Array of objects representing the query results. Each object has properties corresponding to the column names from the query.

### Status

- `reason` (string, required) — Human-readable description of the operation result
- `sql_state` (string, required) — SQL state code (see Error Handling section for common codes)
- `vendor_code` (integer, required) — Vendor-specific error code

### ArrayExecuteResponseSchemaItems

- `name` (string, required) — Column name
- `type` (string, required) — Column data type. Common types include: - INTEGER, BIGINT, SMALLINT (whole numbers) - DOUBLE, REAL, DECIMAL (floating point numbers) - VARCHAR, CHAR, TEXT (text data) - DATE, TIMESTAMP, TIME (temporal data) - BOOLEAN (true/false values) - ARRAY, MAP, TUPLE (complex types)

## Examples

**Response**

```json
{
  "query_id": "550e8400-e29b-41d4-a716-446655440000",
  "status": {
    "reason": "Query executed successfully",
    "sql_state": "00000",
    "vendor_code": 0
  },
  "data": [
    {
      "station_id": "KORD",
      "temperature": 12.5,
      "timestamp": "2023-01-01T12:00:00Z"
    },
    {
      "station_id": "KORD",
      "temperature": 15.3,
      "timestamp": "2023-01-01T13:00:00Z"
    },
    {
      "station_id": "KORD",
      "temperature": 10.2,
      "timestamp": "2023-01-01T14:00:00Z"
    }
  ]
}
```

**SDK Code**

```python python
import requests

token = "YOUR_ACCESS_TOKEN"

response = requests.get(
    "https://your-ocient-instance/v1/execute",
    headers={"Authorization": f"Bearer {token}"},
    params={
        "statement": "SELECT * FROM your_table LIMIT 10",
        "database": "your_database",
        "format": "collection"
    }
)

results = response.json()
print(results)

```

```javascript javascript
const queryParams = new URLSearchParams({
  statement: 'SELECT * FROM your_table LIMIT 10',
  database: 'your_database',
  format: 'collection'
});

const response = await fetch(`https://your-ocient-instance/v1/execute?${queryParams}`, {
  method: 'GET',
  headers: {
    'Authorization': `Bearer ${token}`
  }
});

const results = await response.json();
console.log(results);

```

```go
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://v1/execute?statement=SELECT+*+FROM+customers+LIMIT+10&database=retail_analytics&format=collection&fetch_size=1000"

	req, _ := http.NewRequest("GET", url, nil)

	req.Header.Add("Accept-Encoding", "gzip, deflate, br")
	req.Header.Add("Authorization", "Bearer <token>")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://v1/execute?statement=SELECT+*+FROM+customers+LIMIT+10&database=retail_analytics&format=collection&fetch_size=1000")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Get.new(url)
request["Accept-Encoding"] = 'gzip, deflate, br'
request["Authorization"] = 'Bearer <token>'

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.get("https://v1/execute?statement=SELECT+*+FROM+customers+LIMIT+10&database=retail_analytics&format=collection&fetch_size=1000")
  .header("Accept-Encoding", "gzip, deflate, br")
  .header("Authorization", "Bearer <token>")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('GET', 'https://v1/execute?statement=SELECT+*+FROM+customers+LIMIT+10&database=retail_analytics&format=collection&fetch_size=1000', [
  'headers' => [
    'Accept-Encoding' => 'gzip, deflate, br',
    'Authorization' => 'Bearer <token>',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://v1/execute?statement=SELECT+*+FROM+customers+LIMIT+10&database=retail_analytics&format=collection&fetch_size=1000");
var request = new RestRequest(Method.GET);
request.AddHeader("Accept-Encoding", "gzip, deflate, br");
request.AddHeader("Authorization", "Bearer <token>");
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Accept-Encoding": "gzip, deflate, br",
  "Authorization": "Bearer <token>"
]

let request = NSMutableURLRequest(url: NSURL(string: "https://v1/execute?statement=SELECT+*+FROM+customers+LIMIT+10&database=retail_analytics&format=collection&fetch_size=1000")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "GET"
request.allHTTPHeaderFields = headers

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```