#35419: Add support for creating records from a queryset
-------------------------------------+-------------------------------------
Reporter: c-w | Owner: nobody
Type: New | Status: new
feature |
Component: Database | Version:
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
For performing efficient inserts based on existing data, it would be great
if Django could offer support for the ANSI SQL **INSERT INTO ... SELECT
FROM ...**, perhaps something along the lines of the following snippet:
{{{
queryset = MyTable.objects.filter(field=value)
MyTable.objects.create_from(queryset)
}}}
Currently this type of insertion is only possible by bypassing the ORM or
by evaluating the queryset and then doing a bulk_create. The former is
undesirable for maintainability and the latter is inefficient as it
executes 2 queries and potentially transfers a lot of data over the
network.
The feature has been requested in a few other places such as
[
https://stackoverflow.com/questions/70888534/ StackOverflow] and the
[
https://forum.djangoproject.com/t/14648/ Django Forum] so I figured that
it would be a good idea to open an actual ticket for it.
If the feature request were to be accepted, I can work on a patch for it
if provided with some high-level guidance.
--
Ticket URL: <
https://code.djangoproject.com/ticket/35419>
Django <
https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.