# Query (/docs/nodes/query)



The **Query** node reads directly from a **connection** of your project, either a Postgres database or a Redis, without a service in between. It can only read.

## When to use it [#when-to-use-it]

* Check a customer record or a limit stored in your own database.
* Read a flag, counter or set from Redis.

## How it works [#how-it-works]

<Diagram node="query" kind="anatomy" />

1. Each parameter expression is evaluated and passed to the statement as `$1`, `$2`, ... or as the arguments of the Redis command.
2. **SQL** runs as a single `SELECT` (or `WITH ... SELECT`) inside a read-only transaction, with a timeout and a row cap. **Redis** only accepts read commands such as `GET`, `HGETALL` or `SISMEMBER`.
3. The result is stored: one row (or `null`) in `first` mode, the list of rows in `all` mode.

## Ports [#ports]

| Port      | Taken when                                                                                                                                                 |
| --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Success` | The read succeeded.                                                                                                                                        |
| `Error`   | The call failed and the node is set to continue with a fallback. If Error is not connected, the run carries on through Success with the fallback in place. |

## Configuration [#configuration]

| Field                | What it does                                                    |
| -------------------- | --------------------------------------------------------------- |
| Name                 | Label shown on the canvas and in the trace.                     |
| Connection           | A Postgres or Redis connection from **Settings, Integrations**. |
| Statement or command | The SQL with placeholders, or the Redis command.                |
| Parameters           | One expression per placeholder, in order.                       |
| Mode and max rows    | SQL only: `first` or `all`, and the row cap.                    |
| Store result in      | The variable that receives the result.                          |
| Timeout and on error | `fail` stops the run; `continue` writes a fallback.             |

## What it writes [#what-it-writes]

The result under your variable (`vars.customer.status`). The trace shows the statement summary and the row count, never the secrets.

## In a real flow [#in-a-real-flow]

<Diagram node="query" kind="example" />

The customer status is read from Postgres. An active customer goes on; if the read fails, the run falls back to manual review.

## When it fails [#when-it-fails]

* The read fails or times out: `UPSTREAM_FAILED` (`BLOCKED_URL` for a blocked address), unless on-error continues with a fallback.
* A parameter cannot be computed: `EXPRESSION_FAILED`.
* Checks refuses a statement that is not a single SELECT, a wrong number of parameters, or a Redis command with no key.

## Good to know [#good-to-know]

* Use a read-only database user as well. The database refuses writes, and so should the account.

## Related [#related]

* [Connections](/docs/integrate/connections)
* [API call](/docs/nodes/api-call)
