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
.
insert
or update
, you have to provide a serializable value in the function parameter.upsert
will not return the inserted data. If you want to return the inserted data, you can use the select()
method inside the request.The value(s) you want to insert. `T` can be any serializable type.
Additional configuration & filtering for the request.
val toUpsert = Message(id = 3, message = "foo", username = "supabot")
supabase.from("messages").upsert(toUpsert)
val toUpsert = Message(id = 3, message = "foo", username = "supabot")
val message = supabase.from("messages").upsert(toUpsert) \{
select()
\}.decodeSingle<Message>()
val toUpsert = User(username = "supabot")
supabase.from("users").upsert(toUpsert) \{
onConflict = "username"
\}
val toUpsert = User(username = "supabot")
val count = supabase.from("users").upsert(toUpsert) \{
count(Count.EXACT)
onConflict = "username"
\}.count()