2. Build your first queries

You've seen some examples, you've scoped out your project, and you're ready to get going. The first thing you'll want to do is get some data into the canvas. To do this you'll need to start adding cells.

On this page, we'll be looking at:

  • The 3 ways to add cells to your canvas

  • SQL cells

  • Python cells

3 ways to insert a cell

1. From the Data side bar

To add data directly from the side bar, drag or click "Add to canvas" when you hover over a table or column. You can add data either from your database (in the Tables pane), or from other cells (in the Cells pane).

If you add a table to your canvas, a cell will be created containing a simple SELECT statement.

If you add a column, a visual will be created containing a simple query to represent the distribution of the column.

2. From the tool bar

Select the type of cell you want from the tool bar, and then add the cell to the canvas.

3. From another cell

One of the unique features of the Count canvas is the ability to reference other cells - effectively turning your analysis into a DAG of connected queries. Instead of building messy, complex queries across several tabs in a SQL IDE, visualizing your analysis as a DAG helps because:

  • You can debug a query easily by isolating each subquery or CTE

  • You can copy and paste parts of the DAG for fast iteration and testing

  • The logical steps are easier to follow compared to reading complex nested SQL

Select a cell and hover near one of the edges and a plus icon will appear. Click the plus icon to choose which type of cell to create:

SQL cells

  • Each SQL cell is analagous to a tab of a SQL IDE.

  • Count can execute any SQL SELECT statement.

  • Queries are sent directly to your database, and results are retrieved and shown in the canvas, so use the same syntax you would in your database or SQL IDE.

  • To run a query you can:

    • Click away from the cell

    • Use the Shift + Enter keyboard shortcut

    • Click the Run cell button in the floating cell controls

  • Format the SQL in your cell using the Format SQL button in the Design bar

Editing cells

  • The cell name is the identifier used in code to refer to the cell - ensure that it is a helpful name!

  • You can also add a cell title to help others understand what the cell represents

Python cells

In Count you're not limited to SQL only! Combine SQL with Python to bring a world of opportunity to your analysis.

To learn more about using python in the canvas, see our docs here.

Cell FAQs

What SQL is really running when I reference another cell?

Under the hood, all referenced cells are turned into CTEs, added to the query in your cell, and sent to your database.

To see the SQL that's being run, you can right-click on a cell and click Copy Compiled SQL.

How can I see how long my queries take to run?

On the bottom left of each cell, you will see metadata including:

  • The number of rows, and columns

  • When the query was last executed

  • How long it took to execute the query and download the results

I have some long-running queries, can I stop them from running?

Yes! You can turn caching on for your canvas and that will ensure that queries are only executed when a cell changes. You can also disable automatic cell execution for the entire canvas, or an individual cell.

You can also cancel all pending queries that are currently running:

Can I import existing queries?

Yep! You can import any query consisting of SELECT statements, including compiled dbt models.

Once they are imported you can turn any CTEs into cells in one click, instantly turning your query into a DAG of cells.

Last updated