PostgREST / postgrest

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

Use the filters in POST requests for UPSERTS #3611

Open laurenceisla opened 5 months ago

laurenceisla commented 5 months 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"}]
wolfgangwalther commented 4 months ago

I don't think that's the right thing to do semantically. This smells like PUT, not POST.