Kotlin: 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

val toUpsert = Message(id = 3, message = "foo", username = "supabot")
supabase.from("messages").upsert(toUpsert)

Upsert your data and return it

val toUpsert = Message(id = 3, message = "foo", username = "supabot")
val message = supabase.from("messages").upsert(toUpsert) \{
    select()
\}.decodeSingle<Message>()

Upserting into tables with constraints

val toUpsert = User(username = "supabot")
supabase.from("users").upsert(toUpsert, onConflict = "username")

Return the exact number of rows

val toUpsert = User(username = "supabot")
val count = supabase.from("users").upsert(toUpsert, onConflict = "username") \{
    count(Count.EXACT)
\}.count()