Skip to main content
Version: v2 RC

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().

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

Parameters

  • valuesrequiredRow | array

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

      Properties
    • objectrequiredobject

      No description provided.

    • Rowrequiredobject

      No description provided.

  • optionsrequiredobject

    Named parameters

      Properties
    • countoptionalexact | 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.

        Properties
      • estimatedrequiredliteral

        No description provided.

      • plannedrequiredliteral

        No description provided.

      • exactrequiredliteral

        No description provided.

Examples

Create a record

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

Create a record and return it

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

Bulk create

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

const { error } = await supabase
.from('countries')
.insert([
{ id: 1, name: 'Nepal' },
{ id: 1, name: 'Vietnam' },
])
const { data, error } = await supabase
.from('countries')
.select()