Postgrex.execute

You're seeing just the function execute, go back to Postgrex module for more information.
Link to this function

execute(conn, query, params, opts \\ [])

View Source

Specs

execute(conn(), Postgrex.Query.t(), list(), [execute_option()]) ::
  {:ok, Postgrex.Query.t(), Postgrex.Result.t()} | {:error, Postgrex.Error.t()}

Runs an (extended) prepared query.

It returns the result as {:ok, %Postgrex.Query{}, %Postgrex.Result{}} or {:error, %Postgrex.Error{}} if there was an error. Parameters are given as part of the prepared query, %Postgrex.Query{}.

See the README for information on how Postgrex encodes and decodes Elixir values by default. See Postgrex.Query for the query data and Postgrex.Result for the result data.

Options

  • :queue - Whether to wait for connection in a queue (default: true);
  • :timeout - Execute request timeout (default: 15000);
  • :decode_mapper - Fun to map each row in the result to a term after decoding, (default: fn x -> x end);
  • :mode - set to :savepoint to use a savepoint to rollback to before the execute on error, otherwise set to :transaction (default: :transaction);

Examples

query = Postgrex.prepare!(conn, "", "CREATE TABLE posts (id serial, title text)")
Postgrex.execute(conn, query, [])

query = Postgrex.prepare!(conn, "", "SELECT id FROM posts WHERE title like $1")
Postgrex.execute(conn, query, ["%my%"])