For AI agents: the documentation index is at llms.txt. Guide pages have a markdown version at the same path with .md appended, before any query string or fragment.

C#: Upsert data

Performs an UPSERT into the table.

Examples

Upsert your data

var model = new City
{
  Id = 554,
  Name = "Middle Earth"
};

await supabase.From<City>().Upsert(model);

Upserting into tables with constraints

var model = new City
{
  Id = 554,
  Name = "Middle Earth"
};

await supabase
  .From<City>()
  .OnConflict(x => x.Name)
  .Upsert(model);

Return the exact number of rows

var model = new City
{
  Id = 554,
  Name = "Middle Earth"
};

await supabase
  .From<City>()
  .Upsert(model, new QueryOptions { Count = QueryOptions.CountType.Exact });

Bulk upsert rows with different fields

[Table("cities")]
class City : BaseModel
{
    [PrimaryKey("id", false)]
    public int Id { get; set; }

    [Column("name")]
    public string? Name { get; set; }

    [Column("population", NullValueHandling = JsonIgnoreCondition.WhenWritingNull)]
    public int? Population { get; set; }
}

var rows = new List<City>
{
    new City { Id = 1, Name = "The Shire" },
    new City { Id = 2, Name = "Rivendell", Population = 1200 }
};

await supabase.From<City>().Upsert(rows, new QueryOptions
{
    MissingFields = QueryOptions.MissingFieldType.ColumnDefault
});