Skip to content

Document {:unsafe_fragment, fragment} option for :returning#4711

Merged
josevalim merged 1 commit intoelixir-ecto:masterfrom
henryzhan013:unsafe-fragment-returning-docs
Mar 19, 2026
Merged

Document {:unsafe_fragment, fragment} option for :returning#4711
josevalim merged 1 commit intoelixir-ecto:masterfrom
henryzhan013:unsafe-fragment-returning-docs

Conversation

@henryzhan013
Copy link
Contributor

Document {:unsafe_fragment, fragment} option for :returning

Summary

Documents the new {:unsafe_fragment, fragment} tuple format for the :returning
option, which was added in elixir-ecto/ecto_sql#722

This allows raw SQL expressions in the RETURNING clause (PostgreSQL) and OUTPUT
clause (MSSQL), enabling use cases like:

Repo.insert(changeset,
  on_conflict: {:replace, [:price]},
  conflict_target: :id,
  returning: {:unsafe_fragment, "id, (price != EXCLUDED.price) AS was_updated"}
)

Changes

Added documentation for {:unsafe_fragment, fragment} to the :returning option in:

  • insert_all/3
  • insert/2
  • update/2
  • delete/2

Add documentation for the new {:unsafe_fragment, fragment} tuple format
that can be passed to the :returning option. This allows raw SQL expressions
to be used in the RETURNING clause for PostgreSQL and OUTPUT clause for MSSQL.
@josevalim josevalim merged commit a7f390f into elixir-ecto:master Mar 19, 2026
7 of 8 checks passed
@josevalim
Copy link
Member

💚 💙 💜 💛 ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants