#31565: Support GENERATED ALWAYS columns for MySQL and PostgreSQL
-------------------------------------+-------------------------------------
Reporter: Louise Grandjonc | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Nick Pope):
* stage: Unreviewed => Accepted
Comment:
This would be nice. I'd imagine tweaking your proposed API to look a bit
more like the following:
{{{#!python
class Persistence(enum.Enum):
STORED = 'STORED'
VIRTUAL = 'VIRTUAL'
class People(models.Model):
height_cm = models.FloatField()
height_in = models.FloatField(generated=F('height_cm') / 2.54,
persistence=Persistence.STORED)
}}}
- `always_generated` seems a bit long and it is ''always'' `GENERATED
ALWAYS AS`.
- It would be nice to build expressions using the ORM with `F()`, etc.
- Specifying the "persistence" (is that the best name) keyword with an
enum would allow reuse of that elsewhere.
There are a number of complex issues that need to be addressed:
- The new value needs to be returned on `INSERT` or `UPDATE`. (Support for
`INSERT` via `RETURNING` was added in Django 3.0)
- Any column with `generated` needs to be excluded from `INSERT` or
`UPDATE` queries.
- We'd need to use a feature flag to specify which "persistence" keywords
are supported, i.e. PostgreSQL only supports `STORED`.
--
Ticket URL: <https://code.djangoproject.com/ticket/31565#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/073.7295317597cc1b31f0cca531cfe26fb5%40djangoproject.com.