On this page
Sommatic Docs
Open portal

PostgreSQL - Query

Execute SQL queries on PostgreSQL databases.

View as Markdown
Open in
Integrations Available integrations.postgresql.query Version 1.0.0 Execution: async

Runs one SQL statement on PostgreSQL with positional $1, $2… parameters and returns the rows under result, or routes to empty when no rows come back.

Connect your PostgreSQL instance and run parameterized queries with $1, $2 positional binding for SQL injection prevention. Compatible with PostgreSQL, CockroachDB, Supabase, and Neon.

Operations:

  • SELECT: Fetch rows from tables with filters, joins, and aggregations. Returns empty port when no results.
  • INSERT: Add new records to tables with RETURNING support.
  • UPDATE: Modify existing records matching a condition.
  • DELETE: Remove records from tables.
  • Functions: Call PL/pgSQL functions and stored procedures.
  • DDL: Execute CREATE, ALTER, DROP statements for schema management.

How it works

  1. Resolves the expressions of the node config. Empty connection_id and sql fall back to the incoming item. Parameters are read from params, then parameters, then the incoming item's params or parameters.
  2. Resolves the connection: a postgres:// / postgresql:// URI in connection_id, a connection-string credential, or a basic-auth / object credential with username, password, host, database and port (default 5432).
  3. Connects, runs sql with the parameters (a single non-array value is wrapped in an array) and closes the connection.
  4. Returns { result: rows } on out, or { result: [] } on empty when no rows are returned.

In a workflow

The node as it appears in a workflow file (draft_nodes[]), and the envelope of a successful run.

{
  "node_id": "node-find-customer",
  "label": "Find customer",
  "operator_slug": "integrations.postgresql.query",
  "operator_version": "1.0.0",
  "config": {
    "connection_id": "pi-credential-xxxx",
    "sql": "SELECT id, email, created_at FROM customers WHERE email = $1",
    "parameters": [
      "{{ $json.email }}"
    ]
  }
}

Configuration

connection_id string Required

Credential for your PostgreSQL instance. Accepts credentials of type `connection-string` (postgres:// URI) or `basic-auth` (username + password + host + database).

sql string Required Accepts expressions

The SQL statement to execute (e.g., "SELECT * FROM users WHERE id = $1").

parameters array Optional

Array of values for positional $1, $2, ... parameter binding.

Behaviour in the code

What the implementation does with these keys beyond what the schema says.

params Read by the code, not declared
Undeclared alias of parameters that takes precedence when both are set.
connection_id
With a connection string, TLS is used without certificate verification except for localhost (no TLS). With a structured credential, TLS is used only when the credential config sets ssl.

Output ports

out default

The statement returned at least one row.

Data
{
  "result": [
    {
      "id": 42,
      "email": "ana@example.com",
      "created_at": "2026-11-20T15:04:05.000Z"
    }
  ]
}
empty

The statement returned no rows. This includes INSERT, UPDATE and DELETE without RETURNING.

Data
{
  "result": []
}
error

Validation, credential resolution, the connection or the statement failed.

Data
{
  "error": "relation \"customers\" does not exist"
}

In expressions

What a later node can read from this node's output with $("PostgreSQL - Query").item.json.<path> (write your node's label instead of PostgreSQL - Query). Editor marks the paths the workflow editor suggests under Previous Nodes (the output contract); Worker marks the paths the worker really returns through out, from the output shown in Ports.

ExpressionEditorWorker
$("PostgreSQL - Query").item.json.resultarray= […] (1)Array of rows returned by the query

Errors

Message Port Cause and fix
connection_id is required error No credential in the config or in the incoming item.
sql query is required error sql is empty.
bind message supplies <n> parameters, but prepared statement "" requires <m> error The number of parameters does not match the $n placeholders in sql.
Credential <connection_id> has unsupported type '<type>' for integrations.postgresql.query. Use 'connection-string' or 'basic-auth'. error The credential type is not supported by this node.

Input contract

connection_id string Required
sql string Required
parameters array Optional

Output contract

result array<object> Optional

Array of rows returned by the query

Contracts (JSON Schema)

The definition exactly as the orchestrator declares it. All is the whole *.definition.js; compare it with the sections above to spot differences between the documentation and the schema. Use it to validate a node before you publish.

{
  "slug": "integrations.postgresql.query",
  "name": "PostgreSQL - Query",
  "category": "integrations",
  "version": "1.0.0",
  "description": "Execute SQL queries on PostgreSQL databases.\n\n  Connect your PostgreSQL instance and run parameterized queries with $1, $2 positional binding for SQL injection prevention. Compatible with PostgreSQL, CockroachDB, Supabase, and Neon.\n\n  **Operations:**\n  - **SELECT:** Fetch rows from tables with filters, joins, and aggregations. Returns empty port when no results.\n  - **INSERT:** Add new records to tables with RETURNING support.\n  - **UPDATE:** Modify existing records matching a condition.\n  - **DELETE:** Remove records from tables.\n  - **Functions:** Call PL/pgSQL functions and stored procedures.\n  - **DDL:** Execute CREATE, ALTER, DROP statements for schema management.",
  "capabilities": [
    "sql",
    "database",
    "postgres",
    "postgresql"
  ],
  "group": [
    {
      "key": "postgresql",
      "name": "PostgreSQL",
      "icon_url": "/icons/integrations/postgresql/postgresql.svg"
    }
  ],
  "icon_url": "/icons/integrations/postgresql/postgresql.svg",
  "config_schema": {
    "type": "object",
    "properties": {
      "connection_id": {
        "type": "string",
        "title": "PostgreSQL Credential",
        "description": "Credential for your PostgreSQL instance. Accepts credentials of type `connection-string` (postgres:// URI) or `basic-auth` (username + password + host + database).",
        "ui_widget": "connection_picker",
        "ui_options": {
          "credential_types": [
            "connection-string",
            "basic-auth"
          ],
          "types": [
            "postgres"
          ]
        }
      },
      "sql": {
        "type": "string",
        "title": "SQL Query",
        "description": "The SQL statement to execute (e.g., \"SELECT * FROM users WHERE id = $1\").",
        "format": "expression",
        "ui_widget": "sql_editor"
      },
      "parameters": {
        "type": "array",
        "title": "Query Parameters",
        "description": "Array of values for positional $1, $2, ... parameter binding."
      }
    },
    "required": [
      "connection_id",
      "sql"
    ]
  },
  "input_contract_schema": {
    "type": "object",
    "properties": {
      "connection_id": {
        "type": "string"
      },
      "sql": {
        "type": "string"
      },
      "parameters": {
        "type": "array"
      }
    },
    "required": [
      "connection_id",
      "sql"
    ]
  },
  "output_contract_schema": {
    "type": "object",
    "properties": {
      "result": {
        "type": "array",
        "items": {
          "type": "object"
        },
        "description": "Array of rows returned by the query"
      }
    }
  },
  "ports": [
    {
      "port_id": "out",
      "label": "Rows",
      "description": "Resulting rows from the query",
      "is_default": true,
      "supports_condition": true
    },
    {
      "port_id": "empty",
      "label": "Empty",
      "description": "No rows returned",
      "is_default": false,
      "supports_condition": true
    },
    {
      "port_id": "error",
      "label": "Error",
      "description": "Error occurred during execution",
      "is_default": false,
      "supports_condition": false
    }
  ],
  "execution_mode": "async",
  "required_resources": [],
  "compatible_worker_pools": [
    "standard-io",
    "db-io"
  ],
  "tags": [
    "sql",
    "database"
  ],
  "is_stateful": false,
  "publisher": {
    "identity": "org_sommatic_ai",
    "profile": {
      "name": "Sommatic AI",
      "verified": true,
      "url": "https://sommatic.ai",
      "logo_url": null
    }
  }
}

Execution

Execution
async
Stateful
No
Credentials
Resolved on the server from connection_id; the secret never reaches the workflow.
Capabilities
sqldatabasepostgrespostgresql
Tags
sqldatabase

Notes and limits

  • Use RETURNING on writes if you need out; otherwise they always route to empty.
  • A new connection is opened and closed on every run; the node does not retry.

Reviewed against the orchestrator code · 31e874b · 2026-11-26

Install agent tools

Give your coding agent the official Sommatic AI docs: skills, the docs MCP server and Markdown pages, so it never has to scrape the site.

Skills only. They do not update by themselves; run it again to refresh.

npx skills add https://docs.sommatic.ai
How agents read these docs