Skip to main content
Query lets you write custom analytical queries against your Trigger.dev data. You can execute queries through the dashboard, the SDK, or the REST API.

Available tables

  • runs — all task run data including status, timing, costs, and task output.
  • metrics — metrics data for your runs including CPU, memory, and custom metrics.
Run metadata (key-value pairs set in your task via metadata.set()) is not available in the Query tables. Use runs.retrieve() or the dashboard to inspect metadata.

runs table columns

metrics table columns

See Logging, tracing & metrics for the full list of automatically collected metrics and how to create custom metrics.

prettyFormat()

Use prettyFormat() to format metric values for display:
Available format types: bytes, percent, duration, durationSeconds, quantity, costInDollars.

Using the Query dashboard

Navigate to the Query page in the dashboard to write and run queries. Features include:
  • AI-powered query generation — describe what you want in natural language
  • Syntax highlighting — SQL syntax highlighting for readability
  • Query history — access your previous queries
  • Interactive help — built-in documentation for TRQL syntax and functions
  • Export options — download results as JSON or CSV

Querying from the SDK

Use query.execute() to run TRQL queries programmatically:

Type-safe queries

Use the QueryTable type for inferred result types:

Query options

CSV export

Querying from the REST API

Execute queries via HTTP POST to /api/v1/query:
See the API reference for full details.

TRQL syntax guide

Basic SELECT

Alias columns with AS:
Using SELECT * only returns a subset of core columns for performance reasons. Specify the columns you need explicitly.

Filtering with WHERE

Grouping and aggregation

Sorting and limiting

Available functions

Aggregate functions

Date/time functions

String functions

Conditional functions

JSON functions

The output, error, and metrics.attributes columns are already JSON. Use dot notation to access nested fields — no JSONExtract* needed:

Query scopes

Time ranges

Avoid filtering by triggered_at directly in your query. The dashboard, SDK, and API all support a time filter applied automatically — use period or from/to instead so your queries can be reused across different periods.
Supported period shorthands: 1h, 6h, 12h, 1d, 4d, 7d, 30d, 90d, etc.

Example queries

Set the time filter to 1d in the dashboard or period: "1d" in the SDK.

Best practices

  1. Use the built-in time filter — set period or from/to rather than filtering triggered_at in the query body.
  2. Always add LIMIT — reduce returned rows when you don’t need everything.
  3. Prefer approximate aggregations for large datasets — use uniq() instead of uniqExact() for faster approximate counts.

Limits

Check the Trigger.dev dashboard for current quota details.