Skip to main content
A dynamic query is SQL you save on a datasource under an id, with named parameters, and run by that id. It is the standard way to read data in Wavefront: your application, workflows and agent tools run the same query by name, and the SQL stays on the server. One dynamic query can hold several queries, returning several result sets in one call. For example, a record, its line items and its history together.

Defining a query

Row-level data permissions are applied only where a query contains {{rls}}. A query without it returns every row it selects to any user allowed to run it. Put AND {{rls}} in the WHERE clause of every query that non-admin users run.

Rules of thumb

  • One query per screen or step. A page that shows an order, its lines and its review is one dynamic query with three result sets: one round trip, one place to change.
  • Aggregate in SQL. Dashboards are best served by queries that return counts and sums, not rows to count in code.
  • Add ORDER BY to anything you paginate, so pages are stable.
  • Select the columns you need. Sensitive columns that a caller does not need should not leave the database.

Saving queries

Open the datasource. In its dynamic queries section, use Create Dynamic Query, or upload several YAML files at once. Each query has a Download action that exports its YAML, which is handy for keeping queries in git.

Running a query

Response
Each result set reports its own status and error; check them, because one query of several can fail while the others succeed. Pagination is added for you: LIMIT … OFFSET … is appended to each query, or, if the query already ends with its own top-level LIMIT, it is wrapped as a subquery and paginated outside.
In a workflow, the datasource_execute_query node defaults to 10 rows per result set and bypasses the cache. Prefill limit when you need more rows.

Exporting to CSV

POST /floware/v1/<datasource-id>/dynamic-queries/<id>/export runs a query with the same options and returns CSV. Exports are limited to one every 5 seconds per user.

Other routes

Access

Admins can run every query. Other users need data permissions; their reads are narrowed to the data they are allowed to see. See Users and access.