Query and compute cells
Write SQL query cells and JavaScript compute cells in a notebook, run them, and use their results in other cells.
Use a query cell to run SQL against a connected database, and a compute cell to run JavaScript over the rows that other cells return.
Before you start
- You need permission to edit notebooks. You can't change a notebook marked Read-only.
- A query cell needs a connected database. To add one, see Connect an integration.
- A compute cell reads rows from a SQL, workflow, or compute cell, so add one of those first.
Write and run a query cell
- Open a notebook from Notebooks.
- Select Insert → SQL Query Cell.
- Enter a title in place of Untitled query.
- Enter your SQL in the cell.
- Select Run query, or press CtrlCommand + EnterReturn.
The rows appear under Results. A query that returns nothing shows No rows. Longer results are split into pages.
A query cell holds one SQL statement, for example:
SELECT region, SUM(total) AS revenue
FROM orders
GROUP BY region
ORDER BY revenue DESC;The cell also has these options:
| Option | What it does |
|---|---|
| Table, Bar, Line, Pie | Shows the results as rows or as a chart. |
| Download CSV | Downloads the results as a CSV file. |
| AI Generate | Opens a prompt where you describe the query you want, such as "Show top 10 customers by revenue", and writes the SQL. See AI sections. |
| BigQuery project | For a BigQuery connection, sets the Google Cloud project the query runs in. |
| Delete cell | Removes the cell from the notebook. |
Find tables and columns
The Database Explorer lists your Connected Databases. Use it to check table and column names before you write SQL.
- Enter a name in the search field to filter the list.
- Expand a table to see its columns.
- Select Preview data on a table to open its rows in a tab.
If a database shows Re-authenticate, select it and sign in to that system again.
Write and run a compute cell
- Select Insert → Compute Cell (JS).
- Enter a title in place of Untitled compute.
- Under Inputs, choose the cells whose rows your code reads.
- Enter your JavaScript in the cell.
- Select Run, or press CtrlCommand + EnterReturn.
The cell shows not run until you run it. Its output can then feed chart, pivot table, and metric cells, and other compute cells.
Run every cell
- To run every query in the notebook, select Run all queries or press CtrlCommand + ShiftShift + EnterReturn.
- To run every cell, select Notebook → Run All Cells.
- To empty the results of every cell, select Notebook → Clear All Results.
A cell whose last run failed shows last run failed. Select Run again to retry it.
Use the results in other cells
Chart, pivot table, and metric cells read their rows from a source cell. Add them from Insert → Chart Cell, Insert → Pivot Table, or Insert → Metric Cell.
- A chart cell can read from a SQL, compute, or workflow cell in any section of the notebook.
- The title you gave the query or compute cell is how it appears in the source list.
- A source cell that hasn't run is marked (not run yet). Run it first, and the chart, pivot table, or metric fills in.
Re-run cells on a schedule
- Select Notebook → Scheduled Refresh….
- Choose an interval, from Every 15 minutes to Weekly.
- Select Save.
The notebook re-runs every SQL, compute, and workflow cell at that interval and saves the results. Mark results stale after (hours) sets how old saved results can get before they are marked stale. To stop the schedule, choose Never run on a schedule.
A scheduled run reads shared database connections only. A cell on a private connection still runs when you run it yourself, but fails on the schedule. To include it, see Share a connection.
Troubleshooting
- Query failed. The cell shows the error. Check the SQL and the table and column names against the Database Explorer, then run the cell again.
- Compute failed. Check the code, run the cells listed under Inputs, then run the compute cell again.
- No databases connected. Connect a database in Settings → Integrations, then reopen the notebook.
- A chart, pivot table, or metric cell stays empty. Its source cell hasn't run. Run the source cell.
- Generated SQL uses table or column names that don't exist. No table was referenced, so the SQL assumes the names. In the notebook's AI prompt, type
@and pick a table, then generate again.
↳ AI sections ↳ Embed tiles ↳ Co-editing and export