intermediate7 min read

Create a Workflow

Creating Workflows

Workflows automate tasks based on your database data. A workflow consists of a trigger (when to run), one or more queries (what to check), conditions (what to look for), and actions (what to do).

Anatomy of a Workflow

Every workflow has four parts:

  1. 1Trigger -- what starts the workflow (schedule, webhook, or manual).
  2. 2Query -- a database question or raw SQL that fetches data.
  3. 3Condition -- a rule that determines whether the action should fire (e.g., "if row count > 0" or "if total > $10,000").
  4. 4Action -- what happens when the condition is met (send email, post to Slack, call a webhook, etc.).

Step 1: Create the Workflow

Navigate to Workflows in the sidebar and click New Workflow. Give it a name and optional description.

Step 2: Set the Trigger

Choose when the workflow runs:

  • Scheduled -- run on a cron schedule (every 5 minutes, hourly, daily, etc.)
  • Webhook -- run when an external system sends a POST request to a unique URL
  • Manual -- run only when you click the Run button

Step 3: Define the Query

Add one or more query steps. Each step can be:

  • A natural language question: "Are there any orders placed in the last hour that are still unprocessed?"
  • A saved query from your library
  • Raw SQL for maximum precision

Each query step produces a result set that is available to conditions and subsequent steps.

Step 4: Add Conditions

Conditions evaluate the query results and decide whether to continue:

  • Row count -- "if the query returned more than 0 rows"
  • Value threshold -- "if the total column is greater than 10000"
  • Text match -- "if the status column contains 'error'"
  • Change detection -- "if the value changed since the last run"

Step 5: Configure Actions

When conditions are met, one or more actions execute:

  • Send email -- to specific addresses or dynamically from a query column
  • Post to Slack -- message a channel with the results
  • Call webhook -- send a JSON payload to any URL
  • Run another query -- execute a follow-up query (e.g., update a log table)

Testing

Click Test Run to execute the workflow immediately and see the results of each step. Test runs do not trigger actions by default -- enable "Execute actions in test mode" if you want to send a real notification.

Example: Low Inventory Alert

  1. 1Trigger: Every hour
  2. 2Query: "Show me products where stock_quantity < reorder_level"
  3. 3Condition: Row count > 0
  4. 4Action: Send email to procurement@company.com with the product list