Parameter Queries

A parameter query is an SQL query that runs before the main data source query, producing parameters that are injected into it. This is the primary mechanism for building dynamic, data-aware workflows — especially incremental loading patterns.

How It Works

When you enable Params from SQL Query on a step, you get a secondary SQL editor where you write a parameter query. This query:

  1. Runs against a database of your choice (which can be different from the main data source's database)
  2. Must return a single row (unless iteration is enabled — see below)
  3. Each column in the result becomes a parameter (column name → parameter name)
  4. These parameters are added to the parameters set with the highest priority (Step Query Params)

Example: Incremental Loading

The most common use of parameter queries is fetching a high-water mark from your target table:

Parameter query:

SELECT max(created_at) AS last_created,
  max(updated_at) AS last_updated
FROM my_target_table

This produces the following parameters (values are illustrative):

{
  "last_created": "2018-07-28 12:10:35",
  "last_updated": "2018-07-29 18:42:21"
}

Main data source query can then reference these parameters:

SELECT *
FROM my_table
{{ WHERE created_at >= $last_created }}
   {{ OR updated_at >= $last_updated }}

The SQL-aware interpolation syntax ({{ WHERE ... }}) handles the case where the parameters are NULL (e.g. on the very first run when the target table is empty). See SQL Interpolation for details.

Referencing Other Parameters

Because parameter queries sit at the highest priority level, they can reference parameters from all lower levels — Default Params, Workflow Params, and Step JSON Params.

For example, with a Workflow param of "category_id": 42:

SELECT max(created_at) AS last_imported
FROM my_target_table
WHERE category_id = {{ $category_id }}

This narrows the high-water mark to a specific category — useful when multiple steps import different subsets of data.


Params Iteration

By default, a parameter query must return a single row. When you enable Params Iteration, the behavior changes:

  • The parameter query can return multiple rows
  • The main data source query runs once per row, with parameters set from that row's columns
  • Results from each iteration are combined

The UI hint explains: "This option lets you iterate over a set of parameters. These should come as a result of an SQL Query, or alternatively as an array of JSON Parameters."

Example: Import by Category

Parameter query:

SELECT id AS category_id, name AS category_name
FROM categories
WHERE active = true

Returns (for example) 3 rows. The main query then runs 3 times, once per category:

SELECT *
FROM products
WHERE category_id = {{ $category_id }}

Iteration from JSON Params

Iteration also works with JSON Params instead of a parameter query. If your Step JSON Params contain an array:

[
  { "region": "eu", "schema": "eu_data" },
  { "region": "us", "schema": "us_data" }
]

The main query runs once per array element, with the corresponding keys available as parameters.

This is useful when the set of values to iterate over is static or comes from workflow-level configuration rather than a database query.