mirror of
https://github.com/supabase/supabase.git
synced 2026-07-02 10:44:33 +08:00
95 lines
1.9 KiB
Plaintext
95 lines
1.9 KiB
Plaintext
---
|
|
id: insert
|
|
title: 'Create data: insert()'
|
|
slug: /insert
|
|
custom_edit_url: https://github.com/supabase/supabase/edit/master/spec/supabase_js_v2_legacy.yml
|
|
---
|
|
|
|
import Tabs from '@theme/Tabs'
|
|
import TabItem from '@theme/TabItem'
|
|
|
|
Performs an INSERT into the table.
|
|
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.insert([{ name: 'The Shire', country_id: 554 }])
|
|
```
|
|
|
|
## Parameters
|
|
|
|
<ul className="method-list-group">
|
|
|
|
<li className="method-list-item">
|
|
<h4 className="method-list-item-label">
|
|
<span className="method-list-item-label-name">
|
|
values
|
|
</span>
|
|
<span className="method-list-item-label-badge required">
|
|
required
|
|
</span>
|
|
<span className="method-list-item-validation">
|
|
<code>Row</code> | <code>array</code>
|
|
</span>
|
|
</h4>
|
|
<div class="method-list-item-description">
|
|
|
|
The values to insert.
|
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
<li className="method-list-item">
|
|
<h4 className="method-list-item-label">
|
|
<span className="method-list-item-label-name">
|
|
__namedParameters
|
|
</span>
|
|
<span className="method-list-item-label-badge required">
|
|
required
|
|
</span>
|
|
<span className="method-list-item-validation">
|
|
<code>object</code>
|
|
</span>
|
|
</h4>
|
|
<div class="method-list-item-description">
|
|
|
|
No description provided.
|
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
## Examples
|
|
|
|
### Create a record
|
|
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.insert([{ name: 'The Shire', country_id: 554 }])
|
|
```
|
|
|
|
### Create a record and return it
|
|
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.insert([{ name: 'The Shire', country_id: 554 }])
|
|
.select()
|
|
```
|
|
|
|
### Bulk create
|
|
|
|
When running a bulk create, the operation is handled in a single transaction. If any of the inserts fail, all other operations are
|
|
rolled back.
|
|
|
|
```js
|
|
const { data, error } = await supabase.from('cities').insert([
|
|
{ name: 'The Shire', country_id: 554 },
|
|
{ name: 'Rohan', country_id: 555 },
|
|
])
|
|
```
|