postgrest-py icon indicating copy to clipboard operation
postgrest-py copied to clipboard

Upsert on conflict

Open mansueli opened this issue 1 year ago • 1 comments

It should be possible to use upsert on conflict in supabase-py/postgrest-py client:

https://supabase.com/docs/reference/javascript/upsert#upsert-your-data

const { data, error } = await supabase
  .from('users')
  .upsert({ username: 'supabot' }, { onConflict: 'username' })

Right now, if you are upserting but the ID is auto-generated, then you end up with duplicated entries in the table. Upsert on conflict allows you to prevent duplicated rows based on other columns.

mansueli avatar Jul 12 '22 01:07 mansueli

~~I implemented the solution locally but I'm unable to do pull requests. How should I go about this?~~

UPDATE I have created a pull request that solves this. https://github.com/supabase-community/postgrest-py/pull/142

Oisangui avatar Jul 15 '22 15:07 Oisangui