Executing SQL#

Query your time-series data and metadata with SQL. Each example lists the datasets in your workspace.

In code#

The Python, Rust, and Go examples call the SQL REST API directly. Python reads the REST API URL, API key, and workspace RID from your default profile. For Rust and Go, paste them in from the API keys setup page.

import requests
from nominal.config import NominalConfig

profile = NominalConfig.from_yaml().get_profile("default")

response = requests.post(
    f"{profile.base_url}/sql/v1/query",
    headers={"Authorization": f"Bearer {profile.token}"},
    json={
        "query": "SELECT dataset_rid, name FROM datasets LIMIT 20",
        "workspace_rid": profile.workspace_rid,
        "result_format": "SQL_SERVICE_QUERY_RESULT_FORMAT_CSV",
    },
)
print(response.text)
client = nominal.Client.fromProfile();
t = client.query("SELECT dataset_rid, name FROM datasets LIMIT 20")
// needs the reqwest (with its json feature) and serde_json crates
let api_url = "<api url>";
let api_key = "<api key>"; // DO NOT COMMIT THIS
let workspace_rid = "<workspace rid>";

let csv = reqwest::Client::new()
    .post(format!("{api_url}/sql/v1/query"))
    .bearer_auth(api_key)
    .json(&serde_json::json!({
        "query": "SELECT dataset_rid, name FROM datasets LIMIT 20",
        "workspace_rid": workspace_rid,
        "result_format": "SQL_SERVICE_QUERY_RESULT_FORMAT_CSV",
    }))
    .send().await?
    .text().await?;
println!("{csv}");
import (
	"bytes"
	"encoding/json"
	"io"
	"net/http"
	"os"
)

const apiURL = "<api url>"
const apiKey = "<api key>" // DO NOT COMMIT THIS
const workspaceRid = "<workspace rid>"

body, _ := json.Marshal(map[string]string{
	"query":         "SELECT dataset_rid, name FROM datasets LIMIT 20",
	"workspace_rid": workspaceRid,
	"result_format": "SQL_SERVICE_QUERY_RESULT_FORMAT_CSV",
})
req, _ := http.NewRequest("POST", apiURL+"/sql/v1/query", bytes.NewReader(body))
req.Header.Set("Authorization", "Bearer "+apiKey)
req.Header.Set("Content-Type", "application/json")
resp, _ := http.DefaultClient.Do(req)
io.Copy(os.Stdout, resp.Body)

In the Nominal app#

  1. In the sidebar, click Data, then SQL.

  2. Under Start a query, choose No scope, then type the query, for example SELECT dataset_rid, name FROM datasets LIMIT 20.

  3. Click RUN, or press Ctrl+Enter (⌘+Enter on a Mac).

The results show up to 5,000 rows. To download a full result, see Exporting data by SQL.

For the rest of the console, see 🔒︎SQL console.