mirror of
https://github.com/supabase/supabase.git
synced 2026-06-23 16:44:24 +08:00
102 lines
1.6 KiB
Plaintext
102 lines
1.6 KiB
Plaintext
---
|
|
id: insert
|
|
title: "Create data: insert()"
|
|
slug: insert
|
|
custom_edit_url: https://github.com/supabase/supabase/edit/master/web/spec/dart.yml
|
|
---
|
|
|
|
import Tabs from '@theme/Tabs';
|
|
import TabsPanel from '@theme/TabsPanel';
|
|
|
|
Performs an INSERT into the table.
|
|
|
|
|
|
<Tabs
|
|
defaultActiveId="dart"
|
|
groupId="reference/dart"
|
|
values={[{ label: 'Dart', value: 'dart' }]}>
|
|
|
|
<TabsPanel id="dart" label="dart">
|
|
|
|
```dart
|
|
final res = await supabase
|
|
.from('cities')
|
|
.insert([
|
|
{'name': 'The Shire', 'country_id': 554}
|
|
]).execute();
|
|
```
|
|
|
|
|
|
</TabsPanel>
|
|
|
|
</Tabs>
|
|
|
|
|
|
|
|
|
|
|
|
## Notes
|
|
|
|
- By default, every time you run `insert()`, the client library will make a `select` to return the full record.
|
|
This is convenient, but it can also cause problems if your Policies are not configured to allow the `select` operation.
|
|
If you are using Row Level Security and you are encountering problems, try setting the `returning` param to `minimal`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
### Create a record
|
|
|
|
|
|
|
|
<Tabs
|
|
defaultActiveId="dart"
|
|
groupId="reference/dart"
|
|
values={[{ label: 'Dart', value: 'dart' }]}>
|
|
|
|
<TabsPanel id="dart" label="dart">
|
|
|
|
```dart
|
|
final res = await supabase
|
|
.from('cities')
|
|
.insert([
|
|
{'name': 'The Shire', 'country_id': 554}
|
|
]).execute();
|
|
```
|
|
|
|
|
|
</TabsPanel>
|
|
|
|
</Tabs>
|
|
|
|
### Bulk create
|
|
|
|
|
|
|
|
<Tabs
|
|
defaultActiveId="dart"
|
|
groupId="reference/dart"
|
|
values={[{ label: 'Dart', value: 'dart' }]}>
|
|
|
|
<TabsPanel id="dart" label="dart">
|
|
|
|
```dart
|
|
final res = await supabase
|
|
.from('cities')
|
|
.insert([
|
|
{'name': 'The Shire', 'country_id': 554},
|
|
{'name': 'Rohan', 'country_id': 555},
|
|
]).execute();
|
|
```
|
|
|
|
|
|
</TabsPanel>
|
|
|
|
</Tabs> |