Skip to main content

Overview

The PostgreSQL tool allows you to run SQL queries on a PostgreSQL database.

Key Features

  • POSTGRES_RUN_QUERY
    • Run a SQL query on a PostgreSQL database. Supports SELECT, INSERT, UPDATE, DELETE, and other SQL statements.
    • Inputs: connection (a PostgreSQL connection secret) and query (the SQL to run).
    • Retrieve results in a structured format (columns and rows).

Authentication

Create a POSTGRES secret with your connection details and pass it as the connection input:
  • Host: Hostname of the PostgreSQL server (required).
  • Port: Port number. Defaults to 5432 if omitted.
  • Database: Name of the database to connect to.
  • User: Username to connect with.
  • Password: Password for the user.
  • SSL: Whether to use SSL. Enabled by default; set to false (or disable) to turn it off. The legacy sslmode field is also accepted.
Note: Treat credentials as sensitive information and never commit them to public repositories.

SSL behavior

SSL is enabled by default and server certificates are not strictly verified. If the initial SSL connection fails and SSL was not explicitly disabled, the tool automatically retries without SSL (the server may not support it).

Usage Examples

Example: Run PostgreSQL Query

Example: Query and Summarize with an LLM

Notes

  • Timeouts: The connection attempt times out after 10 seconds, and each statement times out after 30 seconds.
  • Not read-only: Write statements (INSERT, UPDATE, DELETE, DDL) are executed as-is. Use a database user with appropriately scoped privileges.
  • Result serialization: Non-primitive values are converted to strings — dates become ISO 8601 strings, binary (bytea) values become hex strings, and JSON/array/object values are serialized as JSON strings.
  • Non-row-returning statements: Queries that return no result set (e.g., plain INSERT without RETURNING) return empty columns and rows.