Skip to content

Postgres#

Use the Postgres node to automate work in Postgres, and integrate Postgres with other applications. n8n has built-in support for a wide range of Postgres features, including executing queries, as well as inserting and updating rows in a database.

On this page, you'll find a list of operations the Postgres node supports and links to more resources.

Credentials

Refer to Postgres credentials for guidance on setting up authentication.

Examples and templates

For usage examples and templates to help you get started, take a look at n8n's Postgres integrations list.

Operations#

  • Delete
  • Execute Query
  • Insert
  • Insert or Update
  • Select
  • Update

n8n provides a trigger node for Postgres. You can find the trigger node docs here.

View example workflows and related content on n8n's website.

Use query parameters#

When creating a query to run on a Postgres database, you can use the Query Parameters field in the Options section to load data into the query. n8n sanitizes data in query parameters, which prevents SQL injection.

For example, you want to find a person by their email address. Given the following input data:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
[
    {
        "email": "alex@example.com",
        "name": "Alex",
        "age": 21 
    },
    {
        "email": "jamie@example.com",
        "name": "Jamie",
        "age": 33 
    }
]

You can write a query like:

1
SELECT * FROM $1:name WHERE email = $2;

Then in Query Parameters, provide the field values to use. You can provide fixed values or expressions. For this example, use expressions so the node can pull the email address from each input item in turn:

1
2
// users is an example table name
users, {{ $json.email }}