Postgres Block

Execute SQL queries on a PostgreSQL database

The Postgres block enables users to execute SQL queries on a PostgreSQL database within a Scout workflow. It facilitates database interaction by allowing users to specify a connection string and SQL query, with support for Jinja templating to dynamically construct queries based on workflow state.

Configuration (Required)

Connection String
stringRequired

The connection string used to connect to the PostgreSQL database. Ensure this string is correctly formatted and has the necessary permissions to access the database.

SQL Query
codeRequired

The SQL query to execute against the database, supporting dynamic construction using Jinja templating. Use this feature to insert values from the workflow state into your query.

See Workflow Logic & State > State Management for details on using dynamic variables in this block.

Outputs

The output of the Postgres block is a list of dictionaries representing the rows returned by the SQL query, with column names as keys. Additionally, the block provides details such as the response format and the elapsed time in milliseconds for executing the query.

Usage Context

Use this block to perform read operations on a PostgreSQL database, such as retrieving data for further processing in the workflow.

Best Practices

  • Ensure the connection string is correctly formatted and has the necessary permissions.
  • Use Jinja templating in the SQL query to dynamically insert values from the workflow state.
  • Handle exceptions gracefully to manage database connectivity issues or query errors.