Dart Reference v2.0

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.

  • Primary keys must be included in values to use upsert.
Parameters
    values
    REQUIRED
    Map<String, dynamic> or List<Map<String, dynamic>>

    The values to upsert with. Pass a Map to upsert a single row or an List to upsert multiple rows.

    onConflict
    Optional
    String

    Comma-separated UNIQUE column(s) to specify how duplicate rows are determined. Two rows are duplicates if all the onConflict columns are equal.

    ignoreDuplicates
    Optional
    bool

    If true, duplicate rows are ignored. If false, duplicate rows are merged with existing rows.

    defaultToNull
    Optional
    bool

    Make missing fields default to null. Otherwise, use the default value for the column. This only applies when inserting new rows, not when merging with existing rows where ignoreDuplicates is set to false. This also only applies when doing bulk upserts.


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