# SQL Error with n8n and supabase

**URL:** <https://community.n8n.io/t/sql-error-with-n8n-and-supabase/233530>\
**Category:** Questions\
**Tags:** postgres\
**Created:** [December 9, 2025, 1:25pm UTC](https://community.n8n.io/t/sql-error-with-n8n-and-supabase/233530 "2025-12-09T13:25:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![schiker](https://avatars.discourse-cdn.com/v4/letter/s/c68b51/32.png) [@schiker](https://community.n8n.io/u/schiker)\
**Post date:** [December 9, 2025, 1:25pm UTC](https://community.n8n.io/t/sql-error-with-n8n-and-supabase/233530/1 "2025-12-09T13:25:01Z")

</div>

I am using the latest version of n8n (self-hosted by Hostinger) and am trying to write a few lines to a table in a PostgreSQL database (Supabase). The table has several columns, and three of these columns have a constraint key.

_ALTER TABLE inn\_output.message\_dropped_

_ADD CONSTRAINT key\_message\_dropped\_type\_drop\_id\_user\_id UNIQUE (type, drop\_id, user\_id);_

I receive this error in the workflow:

_“duplicate key value violates unique constraint ‘key\_message\_dropped\_type\_drop\_id\_user\_id’_

_Key (type, drop\_id, user\_id)=(news, 387, 1) already exists.”_

The strange thing is that I also get this error when the table is completely empty.

I empty the table with the following SQL:

_TRUNCATE TABLE inn\_output.message\_dropped RESTART IDENTITY;_

I have now spent three hours debugging and cannot find a solution.

Steps I have tried so far:

1. I used the PostgreSQL node instead of the Supabase node, same error.

2. Then I used the PostgreSQL node and executed an SQL directly instead of using the predefined errors, with the same result.

3. I reset the sequence several times, but that didn’t help either.

4. I executed the exact same SQL command in n8n and in Supabase, and it works in Supabase but not in n8n.

Now I’m at my wit’s end. Does anyone else have any useful ideas?

---

<div class="post-metadata">

**Author:** ![salmansolutions](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/salmansolutions/32/144083_2.png) [@salmansolutions](https://community.n8n.io/u/salmansolutions)\
**Post date:** [December 9, 2025, 1:46pm UTC](https://community.n8n.io/t/sql-error-with-n8n-and-supabase/233530/2 "2025-12-09T13:46:23Z")

</div>

Can you provide your n8n workflow as JSON? Excl. all sensitive data of course?  
But preferable with the rows you want to import.

Check how many items are going into your supabase or postgres node.  
Is each item a row? Or are all rows in one item but there are multiple items?  
If it’s more than one item, check if it causes duplicates. Your node gets executed for each sent item.  
if you send more than one item, you most likely will trigger the SQL statement multiple times, causing this error.

---

<div class="post-metadata">

**Author:** ![schiker](https://avatars.discourse-cdn.com/v4/letter/s/c68b51/32.png) [@schiker](https://community.n8n.io/u/schiker)\
**Post date:** [December 9, 2025, 2:28pm UTC](https://community.n8n.io/t/sql-error-with-n8n-and-supabase/233530/3 "2025-12-09T14:28:01Z")

</div>

You solved my problem. Although I told the AI to filter out duplicate IDs, there was still one duplicate ID in the 10 items. The nasty thing is that it’s not visible, and the error message put me on the wrong track. Thank you very much! That was the problem. Apparently, AI cannot perform this task reliably.

---

<div class="post-metadata">

**Author:** ![salmansolutions](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/salmansolutions/32/144083_2.png) [@salmansolutions](https://community.n8n.io/u/salmansolutions)\
**Post date:** [December 9, 2025, 2:34pm UTC](https://community.n8n.io/t/sql-error-with-n8n-and-supabase/233530/4 "2025-12-09T14:34:26Z")

</div>

To remove duplicates I would always use a code node, or the “Remove Duplicates” nodes. This saves you LLM cost and ensures a clean dataset before importing.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/system/32/195824_2.png) [@system](https://community.n8n.io/u/system)\
**Post date:** [December 16, 2025, 2:35pm UTC](https://community.n8n.io/t/sql-error-with-n8n-and-supabase/233530/5 "2025-12-16T14:35:10Z")

</div>

Closed on December 16, 2025, 2:35pm UTC

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