Allow for custom indexes in `onConflict` upsert parameter
Feature request
Is your feature request related to a problem? Please describe.
The upsert method has an optional onConflict which is described in the docs as:
Comma-separated UNIQUE column(s) to specify how duplicate rows are determined. Two rows are duplicates if all the
onConflictcolumns are equal.
I'm trying to do the following:
const { data, error } = await this.supabase.client
.from('my_table')
.upsert(my_data, { onConflict: 'my_custom_unique_index', ignoreDuplicates: true })
.select('*');
and I am getting the following error:
column "my_custom_unique_index" does not exist
Looking under the hood, it looks like the PostgreSQL is being generated like this:
ON CONFLICT("my_custom_unique_index") DO NOTHING
The above sql would work without the double quotes around the index name.
Describe the solution you'd like
A way to specify a unique index to be used in the ON CONFLICT statement, instead of a column name.
I don't know what the js would look like, but an example could be:
const { data, error } = await this.supabase.client
.from('my_table')
.upsert(my_data, { onConflict: 'my_custom_unique_index', onConflictType: 'index', ignoreDuplicates: true })
.select('*');
The above sql would work without the double quotes around the index name.
Can you show an example of that working in plain SQL?
According to postgresql docs, on conflict only works on column names or constraint names.