#31565: Support GENERATED ALWAYS columns for MySQL and PostgreSQL
-------------------------------------+-------------------------------------
               Reporter:  Louise     |          Owner:  nobody
  Grandjonc                          |
                   Type:  New        |         Status:  new
  feature                            |
              Component:  Database   |        Version:  master
  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          |
-------------------------------------+-------------------------------------
 Hi,

 in Postgres 12, generated columns have been added:
 https://www.postgresql.org/docs/12/ddl-generated-columns.html

 The value of a generated column is computed from other columns. A
 generated column can be either stored (in which case it takes up space,
 and is written/updated like any other column) or virtual.

 Here is the example in the postgres docs to create such columns:


 {{{
 CREATE TABLE people (
     ...,
     height_cm numeric,
     height_in numeric GENERATED ALWAYS AS (height_cm / 2.54) STORED
 );
 }}}

 I would love to contribute and add this feature. And I'd like to know a
 bit what other think in terms of design:
 Maybe the expression could be a string:

 {{{
 class People(models.Model):
     height_cm = models.FloatField()
     height_in = models.FloatField(always_generated='height_cm / 2.54',
 stored=True)
 }}}

 Best,
 Louise

-- 
Ticket URL: <https://code.djangoproject.com/ticket/31565>
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/058.4d337b2710f1a5dfc50a82b1c0e86b5b%40djangoproject.com.

Reply via email to