Postgres Query Block

Execute SQL queries on a Postgres database within Scout workflows

The Postgres Query block enables users to execute SQL queries on a Postgres database within Scout workflows. This block can be used to retrieve data from a database, making it available for further processing within Scout workflows. It supports dynamic query templating using Jinja, allowing for the integration of workflow state variables into SQL queries.

Configuration (Required)

Connection String
stringRequired

The connection string is essential for establishing a connection to your Postgres database. It contains all necessary connection details, such as the host, port, database name, user, and password. Ensure this string is formatted correctly to avoid connection issues.

SQL Query
codeRequired

The SQL query defines the specific command or set of commands you wish to execute against your Postgres database. This could range from simple SELECT statements to more complex queries involving joins and aggregations. This field supports Jinja templating for dynamic query construction based on workflow state.

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

Outputs

The output of the Postgres Query block is a list of dictionaries representing the rows returned from the SQL query, with each dictionary containing column-value pairs. This structured output allows for further processing and integration within the workflow.

Usage Context

Use this block to query a Postgres database and retrieve data for use in subsequent workflow steps. This is particularly useful for workflows that need to interact with database systems to fetch or update data based on dynamic conditions.

Best Practices

  • Ensure the connection string is correct and has the necessary permissions to execute the query.
  • Use Jinja templating in the SQL query to dynamically incorporate state variables from your workflow.
  • Handle potential exceptions that may arise from database operations, such as connectivity issues or SQL syntax errors.