Explore data with SQL Lab
SQL Lab is where you explore a connection: look at its tables, answer a question in SQL, and turn the query you end up with into a dataset that charts and dashboards can use.
Run a query
Choose a database
Open SQL Lab and pick a connection under Database. Its tables appear in the schema browser.
Write the query
Type in the editor. Table, column and function names are suggested as you type, and after a table name and a dot, its columns.
SQLSELECT category, SUM(revenue) AS revenue, ROUND(SUM(profit) / SUM(revenue), 3) AS margin FROM Orders GROUP BY category ORDER BY revenue DESCRun it
Choose Run Query or press Ctrl+Enter (⌘+Enter on a Mac). The query runs in the background, so a long one never freezes the page; choose Stop to cancel it.
The schema browser
- Search tables...
- Filter the list by name.
- The arrow beside a table
- Show its columns with their types. Columns load the first time you open a table.
- Selecting a table
- Puts its name in the editor. Double-click, or choose Query beside it, for a ready-made SELECT * query.
If the list says No database connections yet, add one first: see Connect a database or Upload a file.
The toolbar
- Save
- Keep the query as a saved query (see below).
- Dataset
- Save the query as a dataset (see below).
- Query tabs
- Work on several queries at once; + opens a new tab. Open tabs are kept in your browser, so they're still there tomorrow.
- Share
- Copy a link that opens this query, on the same connection, in SQL Lab. Whoever opens it still needs access to that connection.
- Export
- Download the query as a .sql file.
- Last run
- When this tab's query last ran.
Format and explain
Under the editor, beside Run Query:
- Format
- Lay the statement out over lines with consistent indentation, so it's easy to read.
- Explain
- Show the plan the database would follow, without running the query. Use it to find out why a query is slow. Select part of the query to explain just that part.
If the database or DataViz has a warning about a query you ran, it appears at the right of this row.
Results, logs and history
Results appear under the editor, a page at a time. The tabs above them:
- Results
- The rows. Search within them and page through them. If your workspace limits page size, a note says so.
- Execution Log
- What happened: status, connection, schema, row count and the message from the database.
- Query Stats
- Duration, number of rows and number of columns.
- Plan
- The plan from Explain, when you've asked for one.
- History
- Your recent runs. Choose one to put it back in the editor.
Download results
- Download (arrow)
- Save the page of rows on screen as a CSV file.
- Download all (cloud)
- Save every row as CSV. The query is run again a page at a time and the pages are joined; very large results stop at a maximum and say so.
- Expand
- Give the results more of the screen.
Save a query
Choose Save, give the query a name, and choose Save again. Saved queries are listed under Saved Queries in the sidebar for everyone who can read them; see Saved queries and history.
Save a query as a dataset
A query you'll chart, alert on or ask Insight AI about belongs in a dataset. Saving it from SQL Lab keeps the exact SQL you tested.
Choose Dataset
With the query in the editor (run it first, so DataViz knows its columns), choose Dataset.
Name and describe it
Enter a Dataset Name and, under Description / Business Context, what a row is and anything people should know, such as "one row per product category, all orders since January 2025".
Choose the query mode
Direct Query reads the database whenever a chart loads. Import Query stores a snapshot that charts read instead, refreshed on a schedule. See Live or imported.
Save, then chart it
Choose Save. DataViz offers Create Chart, which opens the chart editor with the new dataset already chosen.
Import options
With Import Query chosen, you also set how the snapshot is refreshed:
- Full Refresh
- Run the query again and replace the whole snapshot.
- Semi Refresh
- Add only new or changed rows, found with an Incremental Key: a column that only grows, such as updated_at or an id. Optionally name Unique Key Column(s) to merge changed rows, and a Partition Column to split the stored data.
- Refresh Schedule
- Manual (on demand), Hourly, Daily or Weekly.
Limits and safety
Read-only by default
SQL Lab runs queries that read data. Statements that change data or tables are refused unless the connection allows them (Allow DDL and DML).
Time and row limits
Each query has a time limit and a maximum number of rows, set by your admins under Governance and guardrails. A query that runs past the time limit is stopped with a message saying so.