supabase-js icon indicating copy to clipboard operation
supabase-js copied to clipboard

Example on "upsert into tables with constraint" is wrong

Open wecessary opened this issue 1 year ago • 1 comments

Improve documentation

Link

https://supabase.com/docs/reference/javascript/upsert?example=upserting-into-tables-with-constraints

Describe the problem

The example says that an error will be thrown. But the operation would actually successfully update the row to (42, 'saoirse', 'Saoirse'). Because ignoreDuplicates defaults to false. and the example operation specifies { onConflict: 'handle' }. Therefore it should find row (1, 'saoirse', null) and merge into it.

Describe the improvement

Update the example. I think the example was meant to refer to the case when { onConflict: 'handle' } is NOT specified. Also the doc currently doesn't say what the optional parameters default to.

P.S

I hope I am right about this - otherwise I would be very confused about how upsert works with the client!

wecessary avatar Nov 10 '23 11:11 wecessary

Upsert documentation is indeed very unclear, no default values are specificed, and the example is not working as expected.

What would be the expected combination of options be if one wanted to make sure to merge the data and update the fields? I think this would be the expected behavior.

  • Insert if not exist.
  • IF duplicate exists, based on a field
  • THEN update all other values.

The update part seems not to work in any case. { onConflict: "field_name, ignoreDuplicates: false << to merge the data? }

This set of options is not working for me. Anyone else issues with upsert?

astuanax avatar May 08 '24 12:05 astuanax