Ecto.Repo.update_all

You're seeing just the callback update_all, go back to Ecto.Repo module for more information.
Link to this callback

update_all(queryable, updates, opts)

View Source (optional)

Specs

update_all(
  queryable :: Ecto.Queryable.t(),
  updates :: Keyword.t(),
  opts :: Keyword.t()
) :: {integer(), nil | [term()]}

Updates all entries matching the given query with the given values.

It returns a tuple containing the number of entries and any returned result as second element. The second element is nil by default unless a select is supplied in the update query. Note, however, not all databases support returning data from UPDATEs.

Keep in mind this update_all will not update autogenerated fields like the updated_at columns.

See Ecto.Query.update/3 for update operations that can be performed on fields.

Options

  • :prefix - The prefix to run the query on (such as the schema path in Postgres or the database in MySQL). This overrides the prefix set in the query and any @schema_prefix set in the schema.

See the "Shared options" section at the module documentation for remaining options.

Examples

MyRepo.update_all(Post, set: [title: "New title"])

MyRepo.update_all(Post, inc: [visits: 1])

from(p in Post, where: p.id < 10, select: p.visits)
|> MyRepo.update_all(set: [title: "New title"])

from(p in Post, where: p.id < 10, update: [set: [title: "New title"]])
|> MyRepo.update_all([])

from(p in Post, where: p.id < 10, update: [set: [title: ^new_title]])
|> MyRepo.update_all([])

from(p in Post, where: p.id < 10, update: [set: [title: fragment("upper(?)", ^new_title)]])
|> MyRepo.update_all([])