Flutter: Upsert data

Perform an UPSERT on the table or view. Depending on the column(s) passed to onConflict, .upsert() allows you to perform the equivalent of .insert() if a row with the corresponding onConflict columns doesn't exist, or if it does exist, perform an alternative action depending on ignoreDuplicates.

Examples

Upsert your data

await supabase
  .from('messages')
  .upsert(\{ 'id': 3, 'message': 'foo', 'username': 'supabot' \});

Upserting into tables with constraints

await supabase
  .from('users')
  .upsert(\{ 'username': 'supabot' \}, onConflict: 'username');

Return the exact number of rows

final res = await supabase.from('users').upsert(
  \{'id': 3, 'message': 'foo', 'username': 'supabot'\},
  options: const FetchOptions(count: CountOption.exact),
);

final data = res.data;
final count = res.count;