PostgreSQL

Unified database plugin for PostgreSQL — run raw SQL or structured CRUD operations (query, find, insert, update, delete) from a single node.

When to Use

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

Inputs

HandleTypeDescription
inputanyUpstream data for {{ input.field }} template references in settings fields.

Output

HandleTypeDescription
resultobjectQuery or CRUD operation result

The result (accessed as {{ postgres.* }}) shape:

FieldTypeDescription
rowsarrayResult rows (for query and find; inserted/updated row for insert/update)
affectedRowsnumberNumber of rows affected (for update and delete)
successbooleanWhether the operation succeeded
{
  "rows": [{ "id": 1, "email": "[email protected]" }],
  "affectedRows": 0,
  "success": true
}

Settings

Operation

SettingTypeDefaultDescription
operationenumfindOperation to run: query, find, insert, update, or delete.
allowed_operationsmulti-selectall operationsWhich operations are available when this node is connected to an AI Agent Tools handle. Excluded from the agent tool schema.

Query (showWhen: operation = query)

SettingTypeDefaultDescription
sqlcode editor (SQL)SELECT * FROM users WHERE id = $1Raw SQL query with $1, $2, … positional parameters. Supports {{ }} bindings.
paramscode editor (JSON)[]JSON array of positional parameters for the SQL query. Supports {{ }} bindings.

Table (showWhen: operation = find, insert, update, delete)

SettingTypeDefaultDescription
tablestringPostgreSQL table name (e.g. users, orders). Supports {{ }} bindings.

Filters (showWhen: operation = find, update, delete)

SettingTypeDefaultDescription
wherecode editor (JSON){}WHERE conditions as a key-value object. Supports {{ }} bindings. Required and must not be empty for update and delete.

Data (showWhen: operation = insert, update)

SettingTypeDefaultDescription
datacode editor (JSON){}Column-value mapping for INSERT or SET clause. Supports {{ }} bindings.

Options (showWhen: operation = find)

SettingTypeDefaultDescription
columnsstring*Columns to return (comma-separated). Supports template expression bindings.
limitnumberMaximum number of rows to return. Supports {{ }} bindings.
order_bystringORDER BY clause (e.g. created_at DESC). Supports {{ }} bindings.

Required Secrets

Add your connection string on the Env Vars page:

VariableDescription
DATABASE_URLPostgreSQL 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.

Example

Canvas

Find a user by email after a webhook trigger:

  1. Add a PostgreSQL node after your trigger.
  2. Set Operation to find.
  3. Set Table to users.
  4. Set Where to { "email": "{{ webhook.body.email }}" }.
  5. Set Columns to id, email, name.
  6. 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.

TSL

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

Error Handling

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_URL is missing
  • SQL syntax errors or constraint violations occur
  • update or delete is attempted without a non-empty where clause
  • 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.

Common Gotchas

  • Update and delete require WHERE: Updates and deletes without conditions are rejected at runtime. Always provide a non-empty where object.
  • Positional parameters for raw SQL: Use $1, $2, … in sql and pass values as a JSON array in params — 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 find and query).
  • 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.

See Also

  • 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
On this page