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.

Parameters

Examples

Upsert your data

final data = await supabase
  .from('countries')
  .upsert(\{ 'id': 1, 'name': 'Albania' \})
  .select();

Bulk Upsert your data

final data = await supabase
  .from('countries')
  .upsert([
    \{ 'id': 1, 'name': 'Albania' \},
    \{ 'id': 2, 'name': 'Algeria' \},
  ])
  .select();

Upserting into tables with constraints

final data = await supabase
  .from('users')
  .upsert(\{ 'id': 42, 'handle': 'saoirse', 'display_name': 'Saoirse' \}, \{ onConflict: 'handle' \})
  .select();