Create data: insert()
Performs an INSERT into the table.
- JavaScript
- Python
const { data, error } = await supabase
.from('cities')
.insert([
{ name: 'The Shire', country_id: 554 }
])
Parameters
valuesrequired|
The values to insert.
__namedParametersrequiredobject
No description provided.
onConflictrequired|
By specifying the
on_conflict
query parameter, you can make UPSERT work on a column(s) that has a UNIQUE constraint.upsertrequiredboolean
If
true
, performs an UPSERT.
Properties
Examples
Create a record
- JavaScript
- Python
const { data, error } = await supabase
.from('cities')
.insert([
{ name: 'The Shire', country_id: 554 }
])
Bulk create
- JavaScript
- Python
const { data, error } = await supabase
.from('cities')
.insert([
{ name: 'The Shire', country_id: 554 },
{ name: 'Rohan', country_id: 555 },
])
Upsert
For upsert, if set to true, primary key columns would need to be included in the data parameter in order for an update to properly happen. Also, primary keys used must be natural, not surrogate. There are however, workarounds for surrogate primary keys.
- JavaScript
- Python
const { data, error } = await supabase
.from('cities')
.insert(
[
{ name: 'The Shire', country_id: 554 },
{ name: 'Rohan', country_id: 555 },
{ name: 'City by the Bay', country_id:840}
],
{ upsert: true })