Skip to content

Commit a7f390f

Browse files
authored
Document {:unsafe_fragment, fragment} option for :returning (#4711)
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.
1 parent 299cde2 commit a7f390f

1 file changed

Lines changed: 18 additions & 10 deletions

File tree

lib/ecto/repo.ex

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1655,6 +1655,8 @@ defmodule Ecto.Repo do
16551655
returns all fields in the given schema. May be a list of
16561656
fields, where a struct is still returned but only with the
16571657
given fields. Or `false`, where nothing is returned (the default).
1658+
It also accepts `{:unsafe_fragment, fragment}` to pass a raw SQL
1659+
expression directly to the RETURNING clause (not escaped, use with caution).
16581660
This option is not supported by all databases.
16591661
16601662
* `:prefix` - The prefix to run the query on (such as the schema path
@@ -1822,8 +1824,10 @@ defmodule Ecto.Repo do
18221824
of fields to be returned from the database. When `true`, returns
18231825
all fields, including those marked as `load_in_query: false`. When
18241826
`false`, no extra fields are returned. It will always include all
1825-
fields in `read_after_writes` as well as any autogenerated id. Be
1826-
aware that the fields returned from the database overwrite what was
1827+
fields in `read_after_writes` as well as any autogenerated id.
1828+
It also accepts `{:unsafe_fragment, fragment}` to pass a raw SQL
1829+
expression directly to the RETURNING clause (not escaped, use with caution).
1830+
Be aware that the fields returned from the database overwrite what was
18271831
supplied by the user. Any field not returned by the database will be
18281832
present with the original value supplied by the user. Not all databases
18291833
support this option and it may not be available during upserts.
@@ -2040,10 +2044,12 @@ defmodule Ecto.Repo do
20402044
of fields to be returned from the database. When `true`, returns
20412045
all fields, including those marked as `load_in_query: false`. When
20422046
`false`, no extra fields are returned. It will always include all
2043-
fields in `read_after_writes`. Be aware that the fields returned
2044-
from the database overwrite what was supplied by the user. Any field
2045-
not returned by the database will be present with the original value
2046-
supplied by the user. Not all databases support this option.
2047+
fields in `read_after_writes`. It also accepts `{:unsafe_fragment, fragment}`
2048+
to pass a raw SQL expression directly to the RETURNING clause (not escaped,
2049+
use with caution). Be aware that the fields returned from the database
2050+
overwrite what was supplied by the user. Any field not returned by the
2051+
database will be present with the original value supplied by the user.
2052+
Not all databases support this option.
20472053
20482054
* `:force` - By default, if there are no changes in the changeset,
20492055
`c:update/2` is a no-op. By setting this option to true, update
@@ -2158,10 +2164,12 @@ defmodule Ecto.Repo do
21582164
of fields to be returned from the database. When `true`, returns
21592165
all fields, including those marked as `load_in_query: false`. When
21602166
`false`, no extra fields are returned. It will always include all
2161-
fields in `read_after_writes`. Be aware that the fields returned
2162-
from the database overwrite what was supplied by the user. Any field
2163-
not returned by the database will be present with the original value
2164-
supplied by the user. Not all databases support this option.
2167+
fields in `read_after_writes`. It also accepts `{:unsafe_fragment, fragment}`
2168+
to pass a raw SQL expression directly to the RETURNING clause (not escaped,
2169+
use with caution). Be aware that the fields returned from the database
2170+
overwrite what was supplied by the user. Any field not returned by the
2171+
database will be present with the original value supplied by the user.
2172+
Not all databases support this option.
21652173
21662174
* `:prefix` - The prefix to run the query on (such as the schema path
21672175
in Postgres or the database in MySQL). This overrides the prefix set

0 commit comments

Comments
 (0)