Skip to main content

Database Query

Runs a SQL statement against a database and outputs the rows (or the number of affected rows). It works with PostgreSQL, MySQL (and MariaDB) and Microsoft SQL Server (and Azure SQL), through a Database connection. Values from your workflow are passed as @name parameters, never pasted into the SQL, so they can't change the statement.

You'll find the step in the toolbox under Built-in steps → Core, or search for it.

Settings​

NameRequiredDefaultDescription
Database connectionYes—A PostgreSQL, MySQL or SQL Server connection. The picker only lists Database connections, with a shortcut to create one
ModeYesSelect (return rows)Select (return rows) or Execute (insert / update / delete)
SQLYes—The statement, with @name placeholders for values. Static text: expressions are not allowed here
Query parametersNo—A JSON object with a value for each placeholder. Supports expressions
Max rows (select, up to 10000)No1000Select mode only. The most rows to return, 1–10000
Timeout (seconds)No30How long the statement may run, 1–600

In the workflow JSON the connection is stored as connectionId. Steps saved with the older connection key still work. Selecting a connection that isn't a Database connection is reported as an error when you publish.

The engine (PostgreSQL, MySQL or SQL Server), host, database, sign-in details and SSL mode come from the connection. Sign-in details resolve in the run's environment, so each environment can point at its own database.

Parameters​

Write placeholders as @name in the SQL and give their values in Query parameters:

SELECT id, email, status
FROM orders
WHERE customer_id = @customerId
AND created_at >= @since
ORDER BY created_at DESC
{ "customerId": {{ $trigger.customerId }}, "since": "{{ $today.minus({ days: 7 }).toISO() }}" }
  • @name works the same way in all three databases. Names are matched case-insensitively.
  • Every placeholder needs a value. A missing one fails the step with "No value for @since: add it to the parameters object." Extra values are ignored.
  • Placeholders inside string literals, quoted identifiers and comments are ignored, and so are SQL Server variables such as @@ROWCOUNT and PostgreSQL casts (::date).
  • Values are sent with their type: text, numbers, true / false and null. Objects and lists are sent as JSON text, for example into a jsonb column.
  • Query parameters is evaluated as text first, then parsed as JSON. Put quotes around text values ("{{ … }}") but not around numbers, otherwise PostgreSQL may refuse to compare a text value with a number column. You can also return the whole object from one expression: {{ { customerId: $trigger.customerId, since: $today.toISO() } }}.

:::warning The SQL is static The SQL field is never evaluated as an expression, so workflow data can't change the statement. {{ … }} in the SQL is an error: publishing reports "Expressions ({{ … }}) are not allowed in the SQL. Use @name placeholders and pass the values in 'Query parameters'.", and a run fails with the same message. Pass values through Query parameters. Table and column names can't be parameters: write them in the SQL. :::

Modes​

Select (return rows) reads the result set, up to Max rows. If the query returns more, the extra rows are dropped and truncated is true. Add a LIMIT / TOP or a WHERE to your query rather than relying on the cut-off.

Execute (insert / update / delete) runs the statement and returns the number of affected rows. Use it for INSERT, UPDATE, DELETE and DDL. To get generated values back from an insert, use Select mode with RETURNING (PostgreSQL) or OUTPUT (SQL Server):

INSERT INTO tickets (title, email) VALUES (@title, @email) RETURNING id

Each run opens its own connection and runs the statement on its own. There is no transaction across several steps.

Output​

FieldTypeDescription
rowsArraySelect mode: one object per row, keyed by column name. Empty in execute mode
rowCountNumberThe number of rows in rows
columnsArraySelect mode: the column names, in order
truncatedBooleantrue when more rows than Max rows were available
affectedRowsNumberExecute mode: the rows inserted, updated or deleted
{
"rows": [
{ "id": 1042, "email": "ana@example.com", "status": "paid", "created_at": "2026-11-11T09:30:12.1234560Z" }
],
"rowCount": 1,
"columns": ["id", "email", "status", "created_at"],
"truncated": false,
"affectedRows": 0
}

Dates and times are returned as ISO 8601 text, binary columns as Base64, and NULL as null. When two columns have the same name, the second is renamed (id_2).

{{ $nodes['Database Query'].rows[0].email }}
{{ $nodes['Database Query'].rowCount }}

To run later steps once per row, follow the step with a Split Out on rows or a Loop.

Network access​

The database host must be reachable from the internet. Hosts that resolve to private or internal addresses (loopback, private ranges, link-local, cloud metadata) are refused. Blokkio connects to the address it checked, so a second DNS answer can't redirect the connection. Unix sockets are not supported.

Use a dedicated database user with only the rights the workflow needs, for example a read-only user for Select queries.

Errors​

The step fails with the database's message for syntax errors, missing permissions, a refused login, an unreachable host or a timeout, for example "Database Query: 42P01: relation "order" does not exist". Use the step's error port or retries to handle them.

Self-hosted workers​

Database Query always runs on hosted workers, even when your project is assigned to a self-hosted worker pool. Self-hosted workers never receive connection sign-in details, so Blokkio keeps Database Query steps on hosted workers automatically. The other steps of the workflow still run on your pool.