Skip to main content
A data query is a saved SQL query with a name. It runs against one of your external databases. Write a query once, such as “Monthly MRR”, and your apps and AI coworkers can run it by name instead of each writing their own version. Before you start:
  • Data queries only run against external databases (PostgreSQL, MySQL or Amazon Redshift). They don’t work with integrations, APIs or organization databases.
  • A data query has no parameters. It runs exactly as saved. If you need the same query with different filters, save one query per filter, or let the coworker or app query the database directly.
  • Data queries are visible to your whole organization, and each name must be unique in your organization.
  • You manage data queries under Settings → Data → Data queries. They don’t appear on the Connections page.

Create a data query

1

Open Data queries

Open the user menu at the bottom of the sidebar, choose Settings, then Data queries under Data. Click Create data query.
2

Pick the database

Under External Database, choose the database the query runs against.
3

Name it

Enter a Name that says what the query returns, such as “Active users last 30 days”. Apps and coworkers use this name to run it.
4

Write the query

Write the SQL in Query. When the SQL is valid, a preview of the results appears below it. Otherwise you’ll see “Invalid query”.
5

Save

Click Create data query.
For example, a query named “Monthly MRR” might be:

Run a data query

With a coworker

Ask an AI coworker to run a query by name, or type @ in the message box and pick it from the Integrations section:
Run the “Monthly MRR” data query and chart the last 12 months.
What does “Active users last 30 days” return right now?
In the chat you’ll see “Inspected data query name” when the coworker reads the query’s SQL, and “Ran data query name” when it runs it.

In apps

Apps run data queries by name. The AI in the app editor writes the code, and can run the query while it builds to see the shape of the results:
See Data.

Edit a data query

Click a query in the list to open Update Data Query. You can change the Name and the Query. The database can’t be changed: to run the query against another database, create a new data query. Click Update Data Query to save.
Apps run data queries by name. “If you change this query’s name, it will break existing apps that use this query.” Update those apps, or keep the old name.
SQL changes apply everywhere the query is used, the next time it runs. If apps use the results, keep the same column names, or update the apps too. Only the person who created a data query, or an Owner or Admin, can edit or delete it.

Delete a data query

Click Delete next to the query and confirm in the Delete Data Query dialog. This can’t be undone. Apps that run the query stop working until you update them. Deleting an external database also deletes every data query that uses it.

Tips

  • Use descriptive names. “Open support tickets by priority” is easier to find and reuse than “tickets”.
  • Try it in chat first. Ask a coworker to explore the data and write the SQL with you. Once the results look right, save the SQL as a data query.
  • Keep each query focused. One query should answer one question. Split queries that try to do several things.