Create data: insert()

Perform an INSERT into the table or view.

By default, inserted rows are not returned. To return it, chain the call with .select().

1const { error } = await supabase
2  .from('countries')
3  .insert({ id: 1, name: 'Denmark' })

Parameters#

  • valuesrequired
    Row
    |
    array

    The values to insert. Pass an object to insert a single row or an array to insert multiple rows.

      Properties
    • object
      required
      object

      No description provided.

    • Rowrequired
      object

      No description provided.

  • optionsrequired
    object

    Named parameters

      Properties
    • countoptional
      exact
      |
      planned
      |
      estimated

      Count algorithm to use to count inserted rows.

      "exact": Exact but slow count algorithm. Performs a COUNT(*) under the hood.

      "planned": Approximated but fast count algorithm. Uses the Postgres statistics under the hood.

      "estimated": Uses exact count for low numbers and planned count for high numbers.

Examples#

Create a record#

1create table
2  countries (id int8 primary key, name text);
1const { data, error } = await supabase
2  .from('countries')
3  .select()

Create a record and return it#

1create table
2  countries (id int8 primary key, name text);

Bulk create#

A bulk create operation is handled in a single transaction. If any of the inserts fail, none of the rows are inserted.

1create table
2  countries (id int8 primary key, name text);
1const { data, error } = await supabase
2  .from('countries')
3  .select()