PgRest.SQL.Explain (PgRest v0.2.0)

Copy Markdown View Source

Wraps a compiled statement in EXPLAIN, PostgREST's explainF: the plan of the statement a request would run, for the application/vnd.pgrst.plan media type.

EXPLAIN (FORMAT TEXT | JSON[, ANALYZE][, VERBOSE][, SETTINGS][, BUFFERS][, WAL]) <statement>

The statement and its bind parameters are untouched ($n numbering is unchanged), so the plan shows the values it would run with. Options are a closed set of atoms (PgRest.MediaType), never request text.

Differences from PostgREST

The explained statement is PgRest's own, so the plan's nodes differ from PostgREST's in places: a write adds an aggregate over the rows it wrote (and reads its pgrst_payload CTE), a function call reads a pgrst_rpc CTE where PostgREST reads pgrst_source.

Summary

Types

The format and options of a PgRest.MediaType plan.

Functions

{sql, params} explained. The options follow the order of spec.options, which PgRest.Request.Accept fixes to PostgREST's (analyze, verbose, settings, buffers, wal).

Types

spec()

@type spec() :: %{
  :format => :text | :json,
  :options => [PgRest.MediaType.plan_option()],
  optional(atom()) => term()
}

The format and options of a PgRest.MediaType plan.

Functions

wrap(arg, map)

@spec wrap({String.t(), [term()]}, spec()) :: {String.t(), [term()]}

{sql, params} explained. The options follow the order of spec.options, which PgRest.Request.Accept fixes to PostgREST's (analyze, verbose, settings, buffers, wal).