Skip to content

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

Open
henryzhan013 wants to merge 1 commit intoelixir-ecto:masterfrom
henryzhan013:unsafe-fragment-returning-docs
Open

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

Conversation

@henryzhan013
Copy link

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.
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.

1 participant