Upsert Data
Using either POST or PUT, you can upsert rows.
You can upsert data with POST
and the Prefer: resolution=merge-duplicates
header:
By default, upsert operates based on the primary key columns, you must specify all of them. You can also choose to ignore the duplicates with Prefer: resolution=ignore-duplicates
.
On Conflict
By specifying the on_conflict query parameter, you can make upsert work on a column(s) that has a UNIQUE constraint.
PUT
You can also upsert data with PUT
:
All the columns must be specified in the request body, including the primary key column(s).
Response
If the data was inserted, the response status code will be 201 Created
. If the data was updated, the response status code will be 200 OK
.
The response body will be empty by default, but you can add a select
query parameter to select the columns that should be returned: