PostgreSQL

The PostgreSQL Node allows you to query a PostgreSQL database directly from your workflow. It is designed to take a user’s question (in plain English or SQL), convert it into a SQL query if needed, execute it against your connected PostgreSQL database, and return the results.


Required Inputs

  1. Query (string, required)

    • This is the main input. You can enter your question in plain English (e.g., "Show me the top 10 customers by revenue") or provide a raw SQL query.

    • The node will interpret the plain English query and generate the appropriate SQL, or execute your SQL directly.

  2. Schema (array of strings, optional but recommended)

    • This is where you can provide the database schema (tables, columns, types, etc.) to help the node understand your database structure.

    • Example:

      TABLE Customers (Name TEXT, Email TEXT, Revenue REAL);
      TABLE Orders (OrderID INT, CustomerID INT, Amount REAL);
    • Providing the schema is especially helpful if you want the node to convert plain English to SQL accurately.

Output

  • Query: The actual SQL query that was executed.

  • Results: The results of the query, returned as an array of objects (rows).


Example Usage

  • Plain English Query: Input: "What is the total revenue for the year 2024?" Output: The node will generate the SQL, run it, and return the result.

  • SQL Query: Input: SELECT SUM(revenue) FROM sales WHERE year = 2024; Output: The node will execute this SQL and return the result.


How to Connect

  • If you have a PostgreSQL connection ID, you can add it to the node’s configuration to connect to your specific database.

  • You can connect the output of this node to downstream nodes (like an LLM for analysis, or an Output node for display).


Summary Table

Input Name
Type
Required
Description

query

string

Yes

The question or SQL to execute

sql_schema

array

No

Database schema (tables, columns, types, etc.)

Output Name
Type
Description

query

string

The SQL query that was executed

results

array

The results of the query


If you want to use this node, just provide your question or SQL, and (optionally) the schema. The node will handle the rest—querying your PostgreSQL database and returning the results for use elsewhere in your workflow!

Last updated

Was this helpful?