PostgREST / postgrest

REST API for any Postgres database
https://postgrest.org
MIT License
22.65k stars 1k forks source link

Use the filters in POST requests for UPSERTS #3611

Open laurenceisla opened 1 week ago

laurenceisla commented 1 week ago

Right now, UPSERTS done with POST requests ignore the filters in the query string, e.g:

curl -X POST "localhost:3000/single_unique?on_conflict=unique_key&unique_key=neq.1" \
        -H "Content-Type: application/json" \
        -H "Prefer: resolution=merge-duplicates" \
        -H "Prefer: return=representation" \
        -d '[{ "unique_key": 1, "value": "B" },{ "unique_key": 2, "value": "C" }]'
[{"unique_key":1,"value":"B"},
 {"unique_key":2,"value":"C"}]

But we could make the filter behave like when doing an UPDATE through PATCH. So, unique_key=neq.1 would not be ignored and instead, it would be used in:

-- ...
ON CONFLICT DO
   UPDATE ...
   WHERE <the filter goes here>

Then the previous request would return:

[{"unique_key":2,"value":"C"}]