Databases and Data Table
Sooner or later an automation needs memory: what has already been processed, where the last sync stopped, which record is in which state. n8n offers two routes for that.
An external database — ready-made nodes for Postgres, MySQL, MongoDB and others. The Postgres node's operations are Select, Insert, Update, Insert or Update, Delete and Execute Query.
Data Table — n8n's own structured tabular storage. You can insert, read, update and upsert rows without standing up an external database. It is the ideal middle ground for small state — processed IDs, cursors, configuration.
The rule of thumb: operational data (customers, orders) belongs in an external database; the workflow's own state (what has been processed, where we left off) lives well in a Data Table.
| Operation | What it does | When |
|---|---|---|
| Select | Reads rows; conditions are built in the node UI | Simple reads without writing SQL |
| Insert | Adds new rows; columns can be mapped automatically or by hand | Writing new records |
| Insert or Update | An upsert — updates if it exists, otherwise inserts | The key operation: it makes the workflow idempotent |
| Execute Query | Runs raw SQL; supports parameter tokens like `$1`, `$2` | JOINs, grouping, complex reporting queries |
| Delete | Deletes rows, or an entire table | With care — it cannot be undone |
SQL injection and query parameters. In Execute Query it is tempting to build the query by string concatenation with an expression, but it is dangerous: incoming data can break the query's structure.
The right way is the Query Parameters field. You write $1, $2 tokens in the query and pass the values separately. The official documentation states it plainly: n8n sanitises the data in query parameters, and that prevents SQL injection.
This matters especially because data reaching n8n usually comes from outside — a webhook, a form, an email. Everything from outside must be treated as untrusted.
The Postgres node has a Query Batching setting: send everything as one query, or send them separately. When writing hundreds of items it has a serious effect on performance — one query per item is the slowest option.
📚 Sources and documentation
- Postgres nodeofficialdocs.n8n.io
The operations, and protection from SQL injection via query parameters.
- Data Tableofficialdocs.n8n.io
n8n's built-in tabular storage.
- Data Table node — row operationsofficialdocs.n8n.io