PostgreSQL
Unified database plugin for PostgreSQL — run raw SQL or structured CRUD operations (query, find, insert, update, delete) from a single node.
Use PostgreSQL when you need to:
- Read or write data in a PostgreSQL database from a workflow
- Run parameterized raw SQL for complex queries or joins
- Perform structured CRUD without writing SQL (find, insert, update, delete)
- Give an AI Agent controlled database access via the Tools handle
| Handle | Type | Description |
|---|---|---|
input | any | Upstream data for {{ input.field }} template references in settings fields. |
| Handle | Type | Description |
|---|---|---|
result | object | Query or CRUD operation result |
The result (accessed as {{ postgres.* }}) shape:
| Field | Type | Description |
|---|---|---|
rows | array | Result rows (for query and find; inserted/updated row for insert/update) |
affectedRows | number | Number of rows affected (for update and delete) |
success | boolean | Whether the operation succeeded |
{
"rows": [{ "id": 1, "email": "[email protected]" }],
"affectedRows": 0,
"success": true
}
| Setting | Type | Default | Description |
|---|---|---|---|
operation | enum | find | Operation to run: query, find, insert, update, or delete. |
allowed_operations | multi-select | all operations | Which operations are available when this node is connected to an AI Agent Tools handle. Excluded from the agent tool schema. |
| Setting | Type | Default | Description |
|---|---|---|---|
sql | code editor (SQL) | SELECT * FROM users WHERE id = $1 | Raw SQL query with $1, $2, … positional parameters. Supports {{ }} bindings. |
params | code editor (JSON) | [] | JSON array of positional parameters for the SQL query. Supports {{ }} bindings. |
| Setting | Type | Default | Description |
|---|---|---|---|
table | string | — | PostgreSQL table name (e.g. users, orders). Supports {{ }} bindings. |
| Setting | Type | Default | Description |
|---|---|---|---|
where | code editor (JSON) | {} | WHERE conditions as a key-value object. Supports {{ }} bindings. Required and must not be empty for update and delete. |
| Setting | Type | Default | Description |
|---|---|---|---|
data | code editor (JSON) | {} | Column-value mapping for INSERT or SET clause. Supports {{ }} bindings. |
| Setting | Type | Default | Description |
|---|---|---|---|
columns | string | * | Columns to return (comma-separated). Supports template expression bindings. |
limit | number | — | Maximum number of rows to return. Supports {{ }} bindings. |
order_by | string | — | ORDER BY clause (e.g. created_at DESC). Supports {{ }} bindings. |
Add your connection string on the Env Vars page:
| Variable | Description |
|---|---|
DATABASE_URL | PostgreSQL connection URL (e.g. postgresql://user:password@host:5432/database). See the PostgreSQL connection string docs. |
The plugin uses asyncpg to connect and execute queries.
Find a user by email after a webhook trigger:
- Add a PostgreSQL node after your trigger.
- Set Operation to
find. - Set Table to
users. - Set Where to
{ "email": "{{ webhook.body.email }}" }. - Set Columns to
id, email, name. - Set Limit to
1.
Access results downstream:
{{ postgres.rows[0].id }}
{{ postgres.rows[0].email }}
{{ postgres.success }}
Insert a row from webhook payload:
- Operation:
insert - Table:
orders - Data:
{
"customer_id": "{{ webhook.body.customerId }}",
"amount": "{{ webhook.body.amount }}",
"status": "pending"
}
Connect the On Error branch to handle connection failures or constraint violations.
import webhook from @tensorify/webhook-trigger:4.0.0
import db from @tensorify/postgres:2.0.0
node trigger @tensorify/webhook-trigger:4.0.0 {
path = "/signup"
method = "POST"
}
node find_user @tensorify/postgres:2.0.0 {
operation = "find"
table = "users"
where = "{ \"email\": \"{{ webhook.body.email }}\" }"
columns = "id, email, name"
limit = 1
}
trigger.payload -> find_user.input
PostgreSQL has an On Error control output branch. Enable it via the "Error output handle" toggle at the bottom of the settings panel.
The error branch fires when:
- The database connection fails or
DATABASE_URLis missing - SQL syntax errors or constraint violations occur
updateordeleteis attempted without a non-emptywhereclause- An operation is rejected because it is not in Allowed Operations (Agent) when used as an agent tool
Connect the error branch to a fallback notification or logging action to handle failures without halting the entire workflow.
- Update and delete require WHERE: Updates and deletes without conditions are rejected at runtime. Always provide a non-empty
whereobject. - Positional parameters for raw SQL: Use
$1,$2, … insqland pass values as a JSON array inparams— not string interpolation for user input. - Missing
DATABASE_URL: The node fails at runtime if the env var is not set. Add it on the Env Vars page. - Agent permissions: Restrict Allowed Operations (Agent) for read-only agent access (e.g. allow only
findandquery). - Check
postgres.success: On the main output path, verify{{ postgres.success }}in a downstream If node if you need to branch on failure without using the error handle.
- AI Agent — connect PostgreSQL as a database tool for agents
- Webhook Trigger — trigger database writes from incoming events
- Transform — shape trigger data before insert or update
- If — branch on query results or success status
- Environment Variables — store your
DATABASE_URL
