SQL IDE
Write, save, version, validate, and run SQL against the warehouse. Saved queries are git-backed YAML with parameters, history, and default-deny RBAC.
A git-versioned SQL workbench for the warehouse: write ad-hoc SQL, save it as YAML, template parameters, validate before you run, and gate every read on default-deny RBAC.
You’ll learn:
- How saved queries round-trip through git as YAML artifacts
- How to run a saved query with parameters and per-user templates
- How
AllowQueriesand workspace ACLs gate visibility- How to validate, star, browse trending, and comment on queries
Where the IDE lives
The SQL IDE is the SQL tab in the Goni web app. It talks to the API over a small set of endpoints, all rooted at /api/queries/*, /api/query, /api/sql/validate, /api/snippets, /api/favorites, /api/query_history, /api/views, and /api/trending.
The schema rail on the left and the parameter picker on the right teach you how to compose the first statement.
Note (rate limits): SQL-run endpoints (
POST /api/query,POST /api/queries/{id}/run) live in theheavylimiter class. When you exceed the budget you get429withX-RateLimit-Class: heavyand aRetry-Afterheader.POST /api/sql/validateis a cheap, parse-only check that falls through to the defaultcheapclass. See Rate limiting for class definitions and tuning.
Ad-hoc query: POST /api/query
POST /api/query runs a single statement against the warehouse (or a named connection) without saving anything. It is the endpoint the IDE fires on Run for un-saved SQL. It requires an authenticated session AND the allow_save role bit - a “viewer” that can read dashboards but not author artifacts is deliberately 403’d from the raw IDE. Anonymous callers get 401.
Request shape:
{
"sql": "SELECT count(*) FROM marts_semantic.fct_subscriptions",
"limit": 500,
"connection_id": "warehouse"
}
| Field | Type | Notes |
|---|---|---|
sql | string | Required. Read-only mode is enforced by the warehouse role; the server refuses empty bodies. qr.<id> references are expanded server-side and re-gated per caller. |
limit | int | Optional. If the SQL has no LIMIT clause, the server appends one. Values <=0 or >100000 fall back to the default of 1000. |
connection_id | string | Optional. When set to a non-empty value other than the literal "warehouse", the SQL runs through the named connection instead of the tenant warehouse. Empty, absent, or "warehouse" all route to the legacy warehouse path. |
Example against a named connection:
curl -X POST https://your-goni-host/api/query \
-H "Authorization: Bearer $GONI_PAT" \
-H "Content-Type: application/json" \
-d '{
"sql": "SELECT count(*) FROM public.subscriptions",
"limit": 500,
"connection_id": "acme-prod-postgres"
}'
The connection-routed path bypasses the warehouse cache and the qr.<id> expansion; both fold in for connection queries in a follow-up.
Saved queries are git-versioned YAML
Every saved query lives at queries/{id}.yaml inside the tenant’s git-backed artifact store. Writes go through PUT /api/queries/{id}; the payload is a SavedQuery with id, name, sql, description, parameters[], refresh_schedule, workspace_id, and tags[]. The commit message you pass is the git commit message. Nested parameters survive a save-load cycle.
A saved query looks like this on disk:
id: demo-mrr-by-country
name: 'Demo - MRR by country (last 12 weeks)'
description: >
Sample saved query against the Acme Cloud demo dataset. Shows
weekly MRR broken out by customer country, a classic SaaS exec
view.
sql: |
SELECT
toStartOfWeek(s.started_at) AS week_start,
c.country,
sum(s.mrr_eur) AS mrr_eur,
count() AS active_subscriptions
FROM marts_semantic.fct_subscriptions s
JOIN marts_semantic.dim_customers c
ON c.customer_id = s.customer_id
WHERE s.is_active = 1
AND s.started_at >= toStartOfWeek(now()) - INTERVAL 12 WEEK
GROUP BY week_start, c.country
ORDER BY week_start DESC, mrr_eur DESC
CRUD endpoints
| Method | Path | Permission | Notes |
|---|---|---|---|
| GET | /api/queries | auth + allow_queries filter | Workspace + per-id allow-list applied server-side. |
| GET | /api/queries/{id} | allow_queries match | 404s (not 403) when denied, to prevent id enumeration. |
| PUT | /api/queries/{id} | allow_save | If-Match / ETag optimistic concurrency; author is server-derived. |
| DELETE | /api/queries/{id} | allow_delete | Workspace-gated on the existing artifact before deletion. |
| GET | /api/queries/{id}/history | allow_queries + workspace | Returns the git log for the file. |
| GET | /api/queries/{id}/at/{sha} | allow_queries + workspace | Fetches the YAML as it existed at that SHA. |
| POST | /api/queries/{id}/run | authenticated + allow_queries | Renders template, applies caller identity, runs on the warehouse. |
| POST | /api/query | auth + allow_save | Ad-hoc SQL. Author role is required because the caller is running arbitrary SQL through the IDE. See the section above. |
The Author field is always server-derived from the caller’s session; the browser cannot set it.
Running a saved query
POST /api/queries/{id}/run loads the YAML, substitutes {{ ... }} template references with (a) the authenticated user’s identity, (b) any parameter values from the request body, and (c) wall-clock helpers like today and now, then executes the rendered SQL through the saved-query execution path. That path enforces read-only mode and appends LIMIT when the query does not already have one (default 1000, clamped to 10000; the ad-hoc /api/query endpoint uses a higher 100000 clamp for exploratory work, but the saved-query run cap is tighter because saved queries are the surface dashboards, exports, and scheduled reports bind to).
curl -X POST https://your-goni-host/api/queries/demo-mrr-by-country/run \
-H "Authorization: Bearer $GONI_PAT" \
-H "Content-Type: application/json" \
-d '{"limit": 500}'
The response returns the rendered SQL, the bound parameters, the columns, the rows, cache metadata, and qr_refs (other saved queries this one composed via qr.<id>). Every run is appended to per-user /api/query_history on both success and failure, so a failed query is still traceable.
Note: Saved queries are author-trusted. The run path does not apply metric-style row filters to the rendered SQL. If you want per-user row filtering, template it explicitly:
WHERE owner_email = '{{ current_user }}'.
Snippets and parameters
Snippets live per-user at /api/snippets (GET/POST/DELETE). Clicking a snippet in the IDE sidebar drops its body at the cursor. Anonymous users are 403’d, so the panel hides itself for embed callers.
Parameters are validated on save and rendered at run time. Values are passed in the values object on the run body. The bound parameter list is always echoed back in the response so an auditor can see exactly what plugged into the query.
SQL validation before you run
POST /api/sql/validate returns {ok, errors[]} without touching a warehouse row. The validator first expands qr.<id> references, gates each one against the caller’s permissions (so validate cannot become a probe for restricted query ids), and then validates the expanded SQL against the warehouse dialect.
curl -X POST https://your-goni-host/api/sql/validate \
-H "Authorization: Bearer $GONI_PAT" \
-H "Content-Type: application/json" \
-d '{"sql": "SELECT count(*) FROM marts_semantic.fct_subscriptions"}'
Wire this into your editor’s onChange debounce to flag typos and missing tables before the user hits Run.
Query history, favorites, and trending
GET /api/query_historyreturns your last runs (success and failure), grouped by source (query,adhoc,metric).POST /api/favoriteswith{kind: "query", id: "..."}stars a query;DELETE /api/favorites/{kind}/{id}unstars it.GET /api/favoritespowers the sidebar.POST /api/viewsrecords a view event;GET /api/trending?window=7d&kind=queryreturns the most-viewed queries. Trending is re-gated per caller so it cannot leak query IDs across tenants.
Comments on a query
GET /api/comments?target_kind=query&target_id={id} returns the thread; POST /api/comments appends. Comments are threaded per target, and notifications are produced into the per-user inbox at /api/notifications. Same contract as charts and dashboards, so the comment button is reusable across artifacts.
RBAC: default-deny allow_queries
allow_queries is a per-role field on a role. Empty means deny; wildcards and glob prefixes match. A role that intends broad access must declare ["*"] explicitly, and the seed roles do exactly that.
# policies.yml
roles:
- name: analyst
allow_queries: ["*"]
allow_save: true
row_filters:
raw_acme.subscriptions: "country IN ('LT','LV','EE')"
column_masks:
raw_acme.customers:
email: "hash"
- name: viewer
allow_queries: ["demo-*"]
Row filters and column masks are applied at the metric compile step, not at saved-query run time. A saved query does not run for a role that filters a table it names, or for a role with any column mask: Goni answers 403. Port such a query to a metric to keep the filter or the mask. For the semantics that gate metrics, see Access control.
Related
- Metrics
- Notebooks - narrative surface that runs SQL cells against the same warehouse
- Charts - promote a saved query into a reusable chart
- Access control
- Audit and lineage
- Ask: grounded AI Q&A
- REST API
Last updated