How do I use the `onConflict` option when doing a ...
# javascript
j
How do I use the
onConflict
option when doing a mass insert? What syntax do I need to use? I have a composite unique constraint that consists of two columns. I'm periodically inserting the whole data set and want to just ignore the row if it already exists (or maybe update the
updated_at
column). One tutorial I found suggested the following:
Copy code
ON CONFLICT ON CONSTRAINT customers_name_key 
DO NOTHING
So how would I write that with the supabase JS library?
s
The
ignoreDuplicates
option on upsert does
DO NOTHING
, see: https://supabase.com/docs/reference/javascript/upsert
j
Thanks, I need to try if that works with insert. I think I can't use upsert since I don't have the primary ID
It worked when using upsert and passing a comma separated list of the composite unique key columns:
onConflict: 'product_id, shop_id'
. Not sure why I upsert didn't complain about the missing primary key