Sparround

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.

OperationWhat it doesWhen
SelectReads rows; conditions are built in the node UISimple reads without writing SQL
InsertAdds new rows; columns can be mapped automatically or by handWriting new records
Insert or UpdateAn upsert — updates if it exists, otherwise insertsThe key operation: it makes the workflow idempotent
Execute QueryRuns raw SQL; supports parameter tokens like `$1`, `$2`JOINs, grouping, complex reporting queries
DeleteDeletes rows, or an entire tableWith 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