Opened 3 months ago

Last modified 3 months ago

#29444 assigned New feature

Allow modification of RETURNING values in django.contrib.postgres

Reported by: Johannes Hoppe Owned by: Johannes Hoppe
Component: contrib.postgres Version: master
Severity: Normal Keywords: django, db, returning, default, model, field
Cc: info@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no


Dependency for #27452

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:

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.

Change History (4)

comment:1 Changed 3 months ago by Johannes Hoppe

Version: 2.0master

comment:2 Changed 3 months ago by Johannes Hoppe

Owner: set to Johannes Hoppe
Status: newassigned

comment:3 Changed 3 months ago by Johannes Hoppe

Has patch: set
Last edited 3 months ago by Tim Graham (previous) (diff)

comment:4 Changed 3 months ago by Johannes Hoppe

Patch needs improvement: set
Triage Stage: UnreviewedAccepted
Note: See TracTickets for help on using tickets.
Back to Top