-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Description
Hi,
I'm sorry if this is not the place to ask this question, I wouldn't have if there was a section about it in the documentation.
I'm trying to use Bulk UPSERT with a simple table
create table items (
id serial primary key,
name text
);I then insert these records
curl -X "POST" "http://localhost:5200/items" \
-H 'Content-Type: application/json; charset=utf-8' \
-d $'[
{
"name": "iPad"
},
{
"name": "iPhone"
},
{
"name": "MacBook Pro"
}
]'
When I try to UPSERT with this
## Upsert Items
curl -X "POST" "http://localhost:5200/items" \
-H 'Prefer: resolution=merge-duplicates' \
-H 'Content-Type: application/json' \
-d $'[
{
"id": 1,
"name": "iPad"
},
{
"id": 2,
"name": "iPhone"
},
{
"id": 3,
"name": "Macbook Pro"
},
{
"id": null,
"name": "PostgREST"
}
]'- if I set
idto null in the last item, I get error 400null value in column "id" violates not-null constraint - if I don't include
idin the last item, I get error 400"message":"All object keys must match"
The only way I can get this to work is by providing a value for id, which I can't as id is auto-generated from a sequence, isn't the purpose of UPSERT is to INSERT a new record and in case of conflict with the primary key either update or ignore? how can I insert a new record in this case?
Could you please advice on how this suppose to work? Thanks!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels