Skip to main content

SQL Lab

Starter+

SQL Lab is CalabiIQ's full-featured SQL editor. Write and run queries against any connected database, explore schemas, save queries for reuse, and turn results directly into charts — without leaving the browser.

Tier

SQL Lab is available on all tiers. Advanced features (query history sharing, async long-running queries) require Professional tier.


Opening SQL Lab

  • Click SQLSQL Lab in the top navigation, or
  • Press Alt+Q from anywhere in CalabiIQ.

Interface Overview

┌─────────────────────────────────────────────────────────────────┐
│ Database selector │ Schema selector │ Table browser (left) │
├─────────────────────────────────────────────────────────────────┤
│ │
│ Query editor (top) │
│ │
├─────────────────────────────────────────────────────────────────┤
│ Results table / Query history / Saved queries (bottom tabs) │
└─────────────────────────────────────────────────────────────────┘
PanePurpose
Left sidebarBrowse databases, schemas, tables, and columns
Query editorWrite SQL with syntax highlighting and auto-complete
Results tabTabular output with sorting, searching, and export
Query History tabAll queries run in the current session
Saved Queries tabQueries you have bookmarked for later

Running Queries

Basic run

  1. Select the Database and Schema from the dropdowns.
  2. Write your SQL in the editor.
  3. Click Run or press the keyboard shortcut.

Partial run

Highlight a portion of the SQL, then click Run — only the highlighted text is executed. Useful for testing sub-queries or CTEs.


Keyboard Shortcuts

ShortcutAction
Ctrl+RRun the current query (or selection)
Ctrl+EnterRun the current query (or selection)
Ctrl+Shift+EnterRun the query and format results
Ctrl+SSave the current query
Ctrl+ZUndo last edit
Ctrl+YRedo
Ctrl+/Toggle comment on selected lines
Ctrl+SpaceTrigger auto-complete
Ctrl+ASelect all query text
F11Toggle fullscreen editor

SQL Examples

Count rows in a table

SELECT COUNT(*) AS total_rows
FROM psychometric_reporting.scores;

Exam pass rates by country

SELECT
c.country_name,
COUNT(*) AS total_attempts,
SUM(CASE WHEN s.passed THEN 1 ELSE 0 END) AS passes,
ROUND(
100.0 * SUM(CASE WHEN s.passed THEN 1 ELSE 0 END) / COUNT(*),
2
) AS pass_rate_pct
FROM psychometric_reporting.scores s
JOIN dim.candidates c ON c.candidate_id = s.candidate_id
WHERE s.exam_date >= DATEADD(month, -3, CURRENT_DATE)
GROUP BY c.country_name
ORDER BY pass_rate_pct DESC
LIMIT 20;

Monthly revenue trend (CTE)

WITH monthly AS (
SELECT
DATE_TRUNC('month', created_at) AS month,
SUM(amount_usd) AS revenue
FROM billing.transactions
WHERE status = 'completed'
GROUP BY 1
)
SELECT
month,
revenue,
revenue - LAG(revenue) OVER (ORDER BY month) AS mom_delta
FROM monthly
ORDER BY month;

Find tables with no description

SELECT table_schema, table_name
FROM information_schema.tables
WHERE table_schema NOT IN ('information_schema', 'pg_catalog')
ORDER BY table_schema, table_name;

Schema Explorer

The left sidebar lets you browse your connected databases without writing any SQL:

  1. Expand the database node.
  2. Expand a schema.
  3. Expand a table to see all columns with their data types.
  4. Click the Preview icon next to a table to run SELECT * FROM <table> LIMIT 100 automatically.

Query Tabs

SQL Lab supports multiple tabs — each tab is an independent query editor with its own results.

  • New tab: Click + next to the tab bar.
  • Rename tab: Double-click the tab name.
  • Close tab: Click × on the tab.

Tabs persist for the duration of your browser session. Use Save to persist a query permanently.


Saving Queries

Save frequently-used queries so they are available across sessions and to teammates.

  1. Write the query in the editor.
  2. Press Ctrl+S or click Save (floppy disk icon, toolbar).
  3. Enter a Name and optional Description.
  4. Click Save Query.

Saved queries appear in the Saved Queries tab at the bottom and in SQLSaved Queries from the navigation.

Sharing a saved query

  1. Open SQLSaved Queries.
  2. Find your query and click Share.
  3. Copy the link — any CalabiIQ user with database access can open and run it.

Creating Charts from SQL Results

Turn any SQL result set into a chart without re-building a dataset:

  1. Run a query that produces the columns you want to visualise.
  2. In the Results tab, click Explore.
  3. The Chart Editor opens with a virtual dataset built from your query.
  4. Configure the chart type, metrics, and dimensions as normal.
  5. Save the chart and optionally add it to a dashboard.
tip

Column aliases in your SQL (SELECT COUNT(*) AS total_exams) become the dimension and metric names in the Chart Editor. Use descriptive aliases for cleaner charts.


Downloading Results

FormatHow
CSVResults tab → DownloadCSV
Excel (.xlsx)Results tab → DownloadExcel
JSONResults tab → DownloadJSON

Downloads are limited to 10,000 rows by default. To export larger result sets, use the DataExport feature or contact your Calabi administrator.


Query History

Every query you run is recorded in the Query History tab (bottom of the editor). History shows:

  • Query text
  • Database and schema
  • Run time (ms)
  • Row count
  • Status (success / failed / running)
  • Timestamp

Click any history entry to load the query back into the editor.


Async Queries

Long-running queries (> 30 seconds) are automatically promoted to async mode on Professional+ tenants:

  1. The query is submitted to a background worker.
  2. You can close the tab — the query continues running.
  3. When complete, a notification appears in CalabiIQ.
  4. Find the result in Query History → click Load results.
note

Async queries require the Celery background worker to be running in your Calabi deployment. Contact your administrator if long queries time out.