Serves PUT /<table>?<pk>=eq.<value>: a single-row upsert on the pipeline in
PgRest.Write.Insert.
The URL must carry exactly an eq filter for every primary key column and nothing else
(PGRST105, 405, also for a table without a primary key); limit and offset are
PGRST114 (PgRest.Request.Range). The payload is one object or an array: Postgres reads
every element (a bad value in any is its error) and the statement writes the one whose key
equals the URL's, compared as the column compares (PGRST115 when none, PGRST102 when
several do). plan_put/2 checks the URL and hands Insert a POST shaped request:
resolution=merge-duplicates on the primary key, and no columns=, missing= or
on_conflict= (all ignored, as in PostgREST). Everything else is Insert's: the payload
columns only are updated, over a non-identity scope the conflicting row must be in scope
(PgRest.SQL.Write), and the written row passes the write check, else 42501.
PUT needs :create, :update and :read on the target, because its filters read.
Insert.run/6 answers with PgRest.Responder.put/6: 201 when the row was inserted and 200
when it was updated, with return=representation; 204 for any other return=; no
Content-Range and no Location. max-affected does not bound a PUT. The changeset of a
custom changeset/3 runs with operation: :upsert.
Differences from PostgREST
- A payload without a primary key column, or
[], isPGRST115. PostgREST answers42703(column pgrst_body.name does not exist): its key filter names a body column the payload lacks, an accident rather than a contract. - Several array elements matching the URL are a 400
PGRST102, and nothing is written. PostgREST fails with a 50021000(ON CONFLICT DO UPDATE command cannot affect row a second time), a server error for a client mistake; PgRest, like for aPATCHarray, does not pick one.
Summary
Functions
Validates a PUT and returns the Insert request and the URL key ([{column, text}]) the
statement selects the payload element with (PgRest.SQL.Write.insert/3). The payload objects
must share their keys (PGRST102, as for any write); columns= does not apply to a PUT.
Runs the PUT and sends the response.
Functions
@spec plan_put(PgRest.Request.t(), map()) :: {:ok, PgRest.Request.t(), [{String.t(), String.t()}]} | {:error, PgRest.Error.t()}
Validates a PUT and returns the Insert request and the URL key ([{column, text}]) the
statement selects the payload element with (PgRest.SQL.Write.insert/3). The payload objects
must share their keys (PGRST102, as for any write); columns= does not apply to a PUT.
@spec run(Plug.Conn.t(), map(), map(), PgRest.Request.t(), map()) :: Plug.Conn.t()
Runs the PUT and sends the response.