# UPSERT query in postgres

**URL:** <https://community.n8n.io/t/upsert-query-in-postgres/50444>\
**Category:** Questions\
**Tags:** postgres\
**Created:** [July 20, 2024, 8:22am UTC](https://community.n8n.io/t/upsert-query-in-postgres/50444 "2024-07-20T08:22:10Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![sd35](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@sd35](https://community.n8n.io/u/sd35)\
**Post date:** [July 20, 2024, 8:22am UTC](https://community.n8n.io/t/upsert-query-in-postgres/50444/1 "2024-07-20T08:22:10Z")

</div>

## Describe the problem/error/question

Hello,  
I have a little problem that I don’t understand.  
In a Postgres node I use this query :

## Share the output returned by the last node

```auto
erreur de syntaxe sur ou près de « s »
Failed query: INSERT INTO books (title, price)
VALUES ('Our Band Could Be Your Life: Scenes from the American Indie Underground, 1981-1991', '£57.25')
ON CONFLICT (title) DO NOTHING;

```

If I test the query in postgresql it works fine…  
Any idea ?

Thanks

## Information on your n8n setup

- **n8n version: 1.50.1**
- **Database: PostgreSQL**
- **n8n EXECUTIONS\_PROCESS setting (default: own, main):**
- **Running n8n via: Docker**
- **Operating system: Linux Debian 11**

---

<div class="post-metadata">

**Author:** ![n8n](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/n8n/32/26906_2.png) [@n8n](https://community.n8n.io/u/n8n)\
**Post date:** [July 20, 2024, 8:22am UTC](https://community.n8n.io/t/upsert-query-in-postgres/50444/2 "2024-07-20T08:22:11Z")

</div>

It looks like your topic is missing some important information. Could you provide the following if applicable.

- **n8n version:**
- **Database (default: SQLite):**
- **n8n EXECUTIONS\_PROCESS setting (default: own, main):**
- **Running n8n via (Docker, npm, n8n cloud, desktop app):**
- **Operating system:**

---

<div class="post-metadata">

**Author:** ![ihortom](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/ihortom/32/11473_2.png) [@ihortom](https://community.n8n.io/u/ihortom)\
**Post date:** [July 21, 2024, 1:52am UTC](https://community.n8n.io/t/upsert-query-in-postgres/50444/3 "2024-07-21T01:52:46Z")

</div>

@sd35 , indeed, there seems to be an issue with “Execute Query” operation (though I got a different error). This, however, could be overcome with “Insert” or “Insert or Update” operations (whichever is more suitable)

---

<div class="post-metadata">

**Author:** ![sd35](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@sd35](https://community.n8n.io/u/sd35)\
**Post date:** [July 21, 2024, 6:43am UTC](https://community.n8n.io/t/upsert-query-in-postgres/50444/4 "2024-07-21T06:43:46Z")

</div>

I just tested the insert or update, it works very well. Thank you for the advice.

---

<div class="post-metadata">

**Author:** ![netroy](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/netroy/32/22154_2.png) [@netroy](https://community.n8n.io/u/netroy)\
**Post date:** [July 22, 2024, 5:58pm UTC](https://community.n8n.io/t/upsert-query-in-postgres/50444/5 "2024-07-22T17:58:53Z")

</div>

I’m trying to see if there is a bug here that we need to fix.  
What was the `books` schema like?

I tried this and could not reproduce:

1. `create table books (title varchar primary key, price varchar);`
2. Execute the query from the error you shared

So far I have not been able to reproduce this error on the latest codebase.

---

<div class="post-metadata">

**Author:** ![sd35](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@sd35](https://community.n8n.io/u/sd35)\
**Post date:** [July 22, 2024, 6:48pm UTC](https://community.n8n.io/t/upsert-query-in-postgres/50444/6 "2024-07-22T18:48:52Z")

</div>

here is the table :

```auto
CREATE TABLE books
(
    id SMALLSERIAL UNIQUE ,
    title VARCHAR CONSTRAINT books_pk UNIQUE,
    price VARCHAR
);

```

---

<div class="post-metadata">

**Author:** ![netroy](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/netroy/32/22154_2.png) [@netroy](https://community.n8n.io/u/netroy)\
**Post date:** [July 22, 2024, 6:53pm UTC](https://community.n8n.io/t/upsert-query-in-postgres/50444/7 "2024-07-22T18:53:55Z")

</div>

Thanks. but still not able to reproduce in psql, or on n8n.

 ![image](https://europe1.discourse-cdn.com/n8n/original/3X/4/4/446d58db43b8479a5c6e02fc395b082eb5d0d655.png)  
 ![image](https://europe1.discourse-cdn.com/n8n/original/3X/b/4/b407404b238c9c62c6e17e1b561d938ed6353a46.png)

I don’t see any special characters, so perhaps we can rule out encoding issues 🤔

---

<div class="post-metadata">

**Author:** ![netroy](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/netroy/32/22154_2.png) [@netroy](https://community.n8n.io/u/netroy)\
**Post date:** [July 22, 2024, 6:59pm UTC](https://community.n8n.io/t/upsert-query-in-postgres/50444/8 "2024-07-22T18:59:35Z")

</div>

Can you please check if switching over to parameters fixes this for you?

---

<div class="post-metadata">

**Author:** ![sd35](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@sd35](https://community.n8n.io/u/sd35)\
**Post date:** [July 22, 2024, 7:19pm UTC](https://community.n8n.io/t/upsert-query-in-postgres/50444/9 "2024-07-22T19:19:53Z")

</div>

This method works 🙂

---

<div class="post-metadata">

**Author:** ![sd35](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@sd35](https://community.n8n.io/u/sd35)\
**Post date:** [July 22, 2024, 7:24pm UTC](https://community.n8n.io/t/upsert-query-in-postgres/50444/10 "2024-07-22T19:24:19Z")

</div>

Maybe the problem is the string?

 ![query_error](https://europe1.discourse-cdn.com/n8n/original/3X/3/d/3dadaf775fcce870c70dde9827f35d74173558d2.png)  
And here it works :  
 ![query_ok](https://europe1.discourse-cdn.com/n8n/original/3X/1/9/19b5e2c86d8d57fee3602aaed38e812743c4ce6e.png)

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/system/32/36532_2.png) [@system](https://community.n8n.io/u/system)\
**Post date:** [July 29, 2024, 7:24pm UTC](https://community.n8n.io/t/upsert-query-in-postgres/50444/11 "2024-07-29T19:24:52Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
