The SQL `RETURNING` statement is currently used for inserts of new
objects. Mainly it is responsible to return the primary key in a single
query.
That's great but currently in the postgres database backend this value is
hard coded to only the primary key. I would like to propose to make this
configurable.
There are plenty of uses cases for such a feature ultimately even enabling
database defaults, but I would suggest to keep it very simple for now.
I would suggest to simply allow model fields to specify if they should be
included in the returning statement or not. The default being not (except
PK) to maintain the current behavior.
The implementation as well as the related code lines have been already
discussed here:
https://github.com/django/django/pull/7525#issuecomment-354269077
I highly suggest to keep this a Postgres ONLY feature for now. That way we
can see what sticks and consider extending this functionality into
`django.db` in the future after we have seen how it's being used and
gathered feedback.
--
Ticket URL: <https://code.djangoproject.com/ticket/29444>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* version: 2.0 => master
--
Ticket URL: <https://code.djangoproject.com/ticket/29444#comment:1>
* owner: (none) => Johannes Hoppe
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/29444#comment:2>
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/29444#comment:3>
* needs_better_patch: 0 => 1
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/29444#comment:4>
* needs_better_patch: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/29444#comment:5>
* needs_better_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/29444#comment:6>
* needs_better_patch: 1 => 0
* type: New feature => Cleanup/optimization
--
Ticket URL: <https://code.djangoproject.com/ticket/29444#comment:7>
* needs_better_patch: 0 => 1
* component: contrib.postgres => Database layer (models, ORM)
Comment:
A number of Oracle test failures remain.
--
Ticket URL: <https://code.djangoproject.com/ticket/29444#comment:8>
* needs_better_patch: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/29444#comment:9>
* needs_better_patch: 1 => 0
Comment:
I fixed a couple of things. Nothing fails for me now locally that doesn't
fail on master. Can you trigger it again?
--
Ticket URL: <https://code.djangoproject.com/ticket/29444#comment:9>
Comment (by Tim Graham <timograham@…>):
In [changeset:"b131f9c79f3284f7220c65ceb9125ba4278dc0a4" b131f9c7]:
{{{
#!CommitTicketReference repository=""
revision="b131f9c79f3284f7220c65ceb9125ba4278dc0a4"
Refs #29444 -- Renamed DatabaseFeatures.can_return_id* to be generic for
other columns.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29444#comment:10>
* needs_better_patch: 0 => 1
Comment:
You should be able to trigger the Oracle build yourself as described on
wiki:Jenkins. I ran the tests locally and put the failures in a PR
comment.
--
Ticket URL: <https://code.djangoproject.com/ticket/29444#comment:11>
* needs_better_patch: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/29444#comment:12>
* needs_tests: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/29444#comment:13>
* needs_tests: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/29444#comment:14>
* needs_better_patch: 0 => 1
* has_patch: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/29444#comment:15>
* needs_better_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/29444#comment:15>
* needs_better_patch: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/29444#comment:16>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"bc91f27a86090b4c688b56cd4e37f95eebe6e969" bc91f27a]:
{{{
#!CommitTicketReference repository=""
revision="bc91f27a86090b4c688b56cd4e37f95eebe6e969"
Refs #29444 -- Added support for fetching a returned non-integer insert
values on Oracle.
This is currently not actively used, since the ORM will ask the
SQL compiler to only return auto fields.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29444#comment:17>
* needs_better_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/29444#comment:18>
* needs_better_patch: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/29444#comment:19>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"003bb34b218adb23d1a7e67932a6ba9b3c4dcc81" 003bb34b]:
{{{
#!CommitTicketReference repository=""
revision="003bb34b218adb23d1a7e67932a6ba9b3c4dcc81"
Refs #29444 -- Made db.backends.oracle.utils.InsertVar use str as default.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29444#comment:20>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/29444#comment:21>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"736e7d44de395b867011ff9237dc5fdcfd28ee66" 736e7d44]:
{{{
#!CommitTicketReference repository=""
revision="736e7d44de395b867011ff9237dc5fdcfd28ee66"
Refs #29444 -- Fixed DateField constructor in
db.backends.oracle.utils.InsertVar.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29444#comment:22>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"7254f1138d9c51fa558229c39c9559b369c4278a" 7254f113]:
{{{
#!CommitTicketReference repository=""
revision="7254f1138d9c51fa558229c39c9559b369c4278a"
Refs #29444 -- Allowed returning multiple fields from INSERT statements on
PostgreSQL.
Thanks Florian Apolloner, Tim Graham, Simon Charette, Nick Pope, and
Mariusz Felisiak for reviews.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29444#comment:23>
* Attachment "refs-29444-oracle-part.diff" added.
--
Ticket URL: <https://code.djangoproject.com/ticket/29444>
* has_patch: 1 => 0
* stage: Ready for checkin => Accepted
Comment:
This ticket is doable on Oracle with `cx_Oracle` 6.3+ (see
[https://blogs.oracle.com/opal/python-cx_oracle-63-supports-dml-returning-
for-batch-statement-execution cx_oracle-63-supports-dml-returning-for-
batch-statement]) that's why I'm leaving it open. First attempt of fixing
this on Oracle was a part of the original PR (see
[https://code.djangoproject.com/attachment/ticket/29444/refs-29444-oracle-
part.diff a diff]).
--
Ticket URL: <https://code.djangoproject.com/ticket/29444#comment:24>
* needs_better_patch: 0 => 1
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/11782 PR with adding support on
Oracle]
--
Ticket URL: <https://code.djangoproject.com/ticket/29444#comment:25>
* needs_better_patch: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/29444#comment:26>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"01104368ff77c788f95377e8aceb48772a42fb42" 0110436]:
{{{
#!CommitTicketReference repository=""
revision="01104368ff77c788f95377e8aceb48772a42fb42"
Refs #29444 -- Removed redundant
DatabaseFeatures.can_return_multiple_columns_from_insert.
Unnecessary since b31e63879eb5d9717e9f890401f7222e4f00c910.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29444#comment:28>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"b31e63879eb5d9717e9f890401f7222e4f00c910" b31e6387]:
{{{
#!CommitTicketReference repository=""
revision="b31e63879eb5d9717e9f890401f7222e4f00c910"
Fixed #29444 -- Allowed returning multiple fields from INSERT statements
on Oracle.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29444#comment:27>