> For the complete documentation index, see [llms.txt](https://developer.kizen.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.kizen.com/docs/integrations-and-plugins/integrations/postgres/add-postgres-data-to-an-agentic-workflow.md).

# Add Postgres Data to an Agentic Workflow

{% hint style="success" %}
**Audience:** Admins, Developers, Solution Architects

**Purpose:** Explains how to read and write PostgreSQL data from an <code class="expression">space.vars.automation</code> to query or update your external PostgreSQL database
{% endhint %}

## Overview

{% hint style="warning" %}
**Caution:** This setup reflects Kizen's default configuration. Your administrator may have customized your layout, so columns or navigation may appear differently. Trial accounts may have limited features.
{% endhint %}

Once you set up the Postgres integration in <code class="expression">space.vars.Kizen\_company\_name</code>, you can read and write PostgreSQL data directly from <code class="expression">space.vars.automations</code> with the Read Data and Write Data actions.

***

## Before You Begin

To add Postgres data to an <code class="expression">space.vars.automation</code>, you need:

* A PostgreSQL connection to <code class="expression">space.vars.Kizen\_company\_name</code>. See [Enable Postgres in Kizen](/docs/integrations-and-plugins/integrations/postgres/enable-postgres-in-kizen.md) for details.
* A PostgreSQL user role with the necessary read or write privileges on the target database tables.

***

## Add Postgres data to an Agentic Workflow

To add Postgres data to an <code class="expression">space.vars.automation</code>:

{% stepper %}
{% step %}

#### Go to the Agentic Workflow builder

In the global navigation, select **Agentic Workflows**. Then, to open the builder, do one of the following:

* Select **New Agentic Workflow**.
* Select the name of an existing <code class="expression">space.vars.automation</code>.

<div data-with-frame="true"><figure><img src="/files/lzKaVI7e5AOZZ1FMqBl2" alt="" width="563"><figcaption></figcaption></figure></div>
{% endstep %}

{% step %}

#### Add an action to the workflow

Select **+**, and then select **Add Action**.

<div data-with-frame="true"><figure><img src="/files/61N7OwKwxrL52DHa7sGZ" alt="" width="563"><figcaption></figcaption></figure></div>
{% endstep %}

{% step %}

#### Select the Postgres Connection action

In the Add Action modal that appears, scroll to the Integration section, and select the Postgres Connection card.

<div data-with-frame="true"><figure><img src="/files/MFHp4E2bXHR94E6L68Rh" alt="" width="563"><figcaption></figcaption></figure></div>
{% endstep %}

{% step %}

#### Choose whether to read or write PostgreSQL data

In the Action Settings section of the Add Action modal, select the **Action** dropdown menu, and do one of the following:

* To read PostgreSQL data, select **Read Data**.
* To write PostgreSQL data, select **Write Data**.

<div data-with-frame="true"><figure><img src="/files/Mc0KW0lfXjj5ZrssgM1V" alt="" width="563"><figcaption></figcaption></figure></div>

{% hint style="warning" %}
**Caution:** The Write Data action can insert, update, or delete records in your external PostgreSQL database. Validate your query against a non-production database before running it against production data.
{% endhint %}
{% endstep %}

{% step %}

#### Configure the sources for the script inputs

For each of the fields in the Script Inputs section of the modal, select the source of the field's value from the **Input Source** dropdown menu, and then configure the source with the additional controls that appear.

<div data-with-frame="true"><figure><img src="/files/PDIg7yIZRv3mLyQThTPH" alt="" width="563"><figcaption></figcaption></figure></div>

{% hint style="info" %}
**Note:** The order of the fields on the screen depends on whether you selected the Read Data or Write Data action.
{% endhint %}

The fields are as follows:

| Field                     | Type      | Description                                                                                                                                                                | Required?                                 |
| ------------------------- | --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------- |
| **Query**                 | `String`  | The `SELECT` statement to execute.                                                                                                                                         | Yes                                       |
| **Database**              | `String`  | The name of the target PostgreSQL database.                                                                                                                                | Yes                                       |
| **Connection Secret Tag** | `String`  | The name of the PostgreSQL environment from your integration secret to execute the query on. Configure this source when you have more than one environment in your secret. | Not in a single-environment configuration |
| **Return Single Value**   | `Boolean` | Whether you expect to return a single value (`true`) or multiple values (`false`).                                                                                         | Yes                                       |

{% hint style="info" %}
**Note:** Always use the `LIMIT` clause in `SELECT` queries against large tables. Results sets larger than 5 MB might be truncated or cause memory issues.
{% endhint %}
{% endstep %}

{% step %}

#### Configure the destinations for the script outputs

For each of the fields in the Script Outputs section of the modal, select the destination of the field's value from the **Output Destination** dropdown menu, and then configure the destination with the additional controls that appear.

<div data-with-frame="true"><figure><img src="/files/qeEHRSit4j8xNuAy8Va7" alt="" width="563"><figcaption></figcaption></figure></div>

{% hint style="info" %}
**Note:** The Read Data action uses only the Result field as a script output. The Write Data action uses both Result and Result Status.
{% endhint %}

The fields are as follows:

| Field             | Type     | Action                | Description                       | Required? |
| ----------------- | -------- | --------------------- | --------------------------------- | --------- |
| **Result**        | `String` | Read Data             | The result of the query           | Yes       |
| **Result Status** | `String` | Read Data, Write Data | The status of the write operation | Yes       |
| {% endstep %}     |          |                       |                                   |           |

{% step %}

#### Configure error handling

In the Error Handling section of the modal, specify how to handle errors in this step of the <code class="expression">space.vars.automation</code>.

<div data-with-frame="true"><figure><img src="/files/XYE28AKjBqpeCYQ0sP7S" alt="" width="563"><figcaption></figcaption></figure></div>
{% endstep %}

{% step %}

#### **Save the Postgres Connection action**

Select **Save.**
{% endstep %}
{% endstepper %}

***

## What's Next

Your <code class="expression">space.vars.automation</code> can now read from or write to your PostgreSQL database. For details on how to fix common technical issues, continue to [Troubleshoot Postgres](/docs/integrations-and-plugins/integrations/postgres/troubleshoot-postgres.md).

<details>

<summary><strong>Related Topics</strong></summary>

* [Postgres](/docs/integrations-and-plugins/integrations/postgres.md)
* [Enable Postgres in Kizen](/docs/integrations-and-plugins/integrations/postgres/enable-postgres-in-kizen.md)
* [Troubleshoot Postgres](/docs/integrations-and-plugins/integrations/postgres/troubleshoot-postgres.md)

</details>

***

*Postgres, PostgreSQL, and the Slonik Logo are trademarks or registered trademarks of the PostgreSQL Community Association of Canada. Kizen's PostgreSQL integration is not affiliated with, sponsored by, or endorsed by the PostgreSQL Community Association of Canada, the PostgreSQL Global Development Group, or the PostgreSQL Project.*


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://developer.kizen.com/docs/integrations-and-plugins/integrations/postgres/add-postgres-data-to-an-agentic-workflow.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
