[Django] #31300: Add Generated Columns (PostgreSQL) support

253 views
Skip to first unread message

Django

unread,
Feb 22, 2020, 6:34:16 AM2/22/20
to django-...@googlegroups.com
#31300: Add Generated Columns (PostgreSQL) support
-------------------------------------+-------------------------------------
Reporter: | Owner: nobody
Dulmandakh |
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 |
-------------------------------------+-------------------------------------
PostgreSQL 12 added support for Generated Columns, see
https://www.postgresql.org/docs/12/ddl-generated-columns.html. And I find
it very interesting and useful, for example with SearchVectorField.

I imagine it would be called GeneratedField and accept base_field as
ArrayField, then expression to generate a value for the field. For
example,

{{{
class Album(models.Model):
...
title = models.CharField(max_length=120)
search = GeneratedField(
SearchVectorField(),
F('title')
)
}}}

then generate SQL something like below.

{{{
CREATE TABLE album (
...
title char(120),
search tsvector GENERATED ALWAYS AS title STORED
);
}}}

I would like to work on this feature, but don't know how to pass
expression and generate migration using the expression.

--
Ticket URL: <https://code.djangoproject.com/ticket/31300>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Feb 25, 2020, 2:37:12 AM2/25/20
to django-...@googlegroups.com
#31300: Add function-based virtual fields on PostgreSQL and Oracle.
-------------------------------------+-------------------------------------
Reporter: Dulmandakh | Owner: nobody
Type: New feature | Status: closed
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* status: new => closed
* resolution: => wontfix


Comment:

We have an accepted ticket #30511 about identity columns on PostgreSQL,
and I think we should stay with this. Generated/Function-based virtual
columns are a huge topic that would require many changes and have many
caveats, e.g. functions must be deterministic. They are feasible also on
Oracle. This kind of features require few weeks (even months) of works, a
precise plan, and should be preceded by a discussion on
DevelopersMailingList and even DEP.

--
Ticket URL: <https://code.djangoproject.com/ticket/31300#comment:1>

Django

unread,
Apr 24, 2021, 2:47:40 AM4/24/21
to django-...@googlegroups.com
#31300: Add function-based virtual fields on PostgreSQL and Oracle.
-------------------------------------+-------------------------------------
Reporter: Dulmandakh | Owner: nobody
Type: New feature | Status: closed
Component: Database layer | Version: dev

(models, ORM) |
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Petr Přikryl):

* cc: Petr Přikryl (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/31300#comment:2>

Django

unread,
Jan 2, 2023, 1:57:38 AM1/2/23
to django-...@googlegroups.com
#31300: Add function-based virtual fields.

-------------------------------------+-------------------------------------
Reporter: Dulmandakh | Owner: nobody
Type: New feature | Status: new

Component: Database layer | Version: dev
(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 Mariusz Felisiak):

* status: closed => new
* resolution: wontfix =>
* stage: Unreviewed => Accepted


Comment:

Tentatively accepted, based on the [https://groups.google.com/g/django-
developers/c/9Mf7YqDA4bg/m/wb07E71oAAAJ feedback] from the mailing list.

--
Ticket URL: <https://code.djangoproject.com/ticket/31300#comment:3>

Django

unread,
Jan 2, 2023, 1:58:33 AM1/2/23
to django-...@googlegroups.com
#31300: Add function-based virtual fields.
-------------------------------------+-------------------------------------
Reporter: Dulmandakh | Owner: Jeremy
| Nauta
Type: New feature | Status: assigned

Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* owner: nobody => Jeremy Nauta
* needs_better_patch: 0 => 1
* has_patch: 0 => 1
* status: new => assigned


Comment:

[https://github.com/django/django/pull/16417 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/31300#comment:4>

Django

unread,
Jan 11, 2023, 4:10:58 AM1/11/23
to django-...@googlegroups.com
#31300: Add function-based virtual fields.
-------------------------------------+-------------------------------------
Reporter: Dulmandakh | Owner: Jeremy
| Nauta
Type: New feature | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by elonzh):

* cc: elonzh (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/31300#comment:5>

Django

unread,
Mar 27, 2023, 6:28:50 AM3/27/23
to django-...@googlegroups.com
#31300: Add function-based virtual fields.
-------------------------------------+-------------------------------------
Reporter: Dulmandakh | Owner: Jeremy
| Nauta
Type: New feature | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Paolo Melchiorre):

* needs_better_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/31300#comment:6>

Django

unread,
Mar 27, 2023, 7:42:53 AM3/27/23
to django-...@googlegroups.com
#31300: Add function-based virtual fields.
-------------------------------------+-------------------------------------
Reporter: Dulmandakh | Owner: Jeremy
| Nauta
Type: New feature | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/31300#comment:7>

Django

unread,
Apr 7, 2023, 2:31:28 PM4/7/23
to django-...@googlegroups.com
#31300: Add function-based virtual fields.
-------------------------------------+-------------------------------------
Reporter: Dulmandakh | Owner: Jeremy
| Nauta
Type: New feature | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jeremy Nauta):

* needs_better_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/31300#comment:8>

Django

unread,
Jun 20, 2023, 4:08:31 AM6/20/23
to django-...@googlegroups.com
#31300: Add function-based virtual fields.
-------------------------------------+-------------------------------------
Reporter: Dulmandakh | Owner: Jeremy
| Nauta
Type: New feature | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Lily Foote):

* cc: Lily Foote (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/31300#comment:9>

Django

unread,
Jul 3, 2023, 4:44:04 AM7/3/23
to django-...@googlegroups.com
#31300: Add function-based virtual fields.
-------------------------------------+-------------------------------------
Reporter: Dulmandakh | Owner: Jeremy
| Nauta
Type: New feature | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: field, database, | Triage Stage: Accepted
generated |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Paolo Melchiorre):

* cc: Paolo Melchiorre (added)
* keywords: => field, database, generated


--
Ticket URL: <https://code.djangoproject.com/ticket/31300#comment:10>

Django

unread,
Jul 21, 2023, 9:05:53 PM7/21/23
to django-...@googlegroups.com
#31300: Add function-based virtual fields.
-------------------------------------+-------------------------------------
Reporter: Dulmandakh | Owner: Jeremy
| Nauta
Type: New feature | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: field, database, | Triage Stage: Ready for
generated | checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jeremy Nauta):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/31300#comment:11>

Django

unread,
Jul 22, 2023, 1:54:30 PM7/22/23
to django-...@googlegroups.com
#31300: Add function-based virtual fields.
-------------------------------------+-------------------------------------
Reporter: Dulmandakh | Owner: Jeremy
| Nauta
Type: New feature | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: field, database, | Triage Stage: Accepted
generated |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* stage: Ready for checkin => Accepted


Comment:

Jeremy, you cannot mark your own patches as RFC, check out
[https://docs.djangoproject.com/en/4.2/internals/contributing/triaging-
tickets/#ready-for-checkin docs].

--
Ticket URL: <https://code.djangoproject.com/ticket/31300#comment:12>

Django

unread,
Jul 27, 2023, 5:25:05 AM7/27/23
to django-...@googlegroups.com
#31300: Add function-based virtual fields.
-------------------------------------+-------------------------------------
Reporter: Dulmandakh | Owner: Jeremy
| Nauta
Type: New feature | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: field, database, | Triage Stage: Ready for
generated | checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Paolo Melchiorre):

* stage: Accepted => Ready for checkin


Comment:

Mariusz if I have interpreted the documentation correctly, having just
reviewed it again and not being the author of the PR, I have marked it as
an RFC.

--
Ticket URL: <https://code.djangoproject.com/ticket/31300#comment:13>

Django

unread,
Jul 27, 2023, 5:29:10 AM7/27/23
to django-...@googlegroups.com
#31300: Add function-based virtual fields.
-------------------------------------+-------------------------------------
Reporter: Dulmandakh | Owner: Jeremy
| Nauta
Type: New feature | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: field, database, | Triage Stage: Ready for
generated | checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Lily Foote):

One thing that might help this land is review of the Oracle support I
added in https://github.com/django/django/pull/16860. There's a few open
questions that could use thought from more people.

--
Ticket URL: <https://code.djangoproject.com/ticket/31300#comment:14>

Django

unread,
Jul 27, 2023, 5:46:00 AM7/27/23
to django-...@googlegroups.com
#31300: Add function-based virtual fields.
-------------------------------------+-------------------------------------
Reporter: Dulmandakh | Owner: Jeremy
| Nauta
Type: New feature | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: field, database, | Triage Stage: Ready for
generated | checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Paolo Melchiorre):

I personally can't help with Oracle testing, as I believe many others
here, but if there weren't other people able to help, as Adam has already
suggested [1] in the PR comments, I wouldn't block the merge of this
feature because it lacks the Oracle support given how little it is used.

[1] https://github.com/django/django/pull/16417#issuecomment-1508222534

--
Ticket URL: <https://code.djangoproject.com/ticket/31300#comment:15>

Django

unread,
Aug 7, 2023, 1:55:06 PM8/7/23
to django-...@googlegroups.com
#31300: Add function-based virtual fields.
-------------------------------------+-------------------------------------
Reporter: Dulmandakh | Owner: Jeremy
| Nauta
Type: New feature | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: field, database, | Triage Stage: Ready for
generated | checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by jul...@pinabausch.org):

* cc: jul...@pinabausch.org (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/31300#comment:16>

Django

unread,
Sep 4, 2023, 3:31:46 AM9/4/23
to django-...@googlegroups.com
#31300: Add function-based virtual fields.
-------------------------------------+-------------------------------------
Reporter: Dulmandakh | Owner: Jeremy
| Nauta
Type: New feature | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: field, database, | Triage Stage: Accepted
generated |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* needs_better_patch: 0 => 1


* stage: Ready for checkin => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/31300#comment:17>

Django

unread,
Sep 7, 2023, 12:21:23 AM9/7/23
to django-...@googlegroups.com
#31300: Add function-based virtual fields.
-------------------------------------+-------------------------------------
Reporter: Dulmandakh | Owner: Jeremy
| Nauta
Type: New feature | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: field, database, | Triage Stage: Ready for
generated | checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* needs_better_patch: 1 => 0


* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/31300#comment:18>

Django

unread,
Sep 7, 2023, 4:07:30 AM9/7/23
to django-...@googlegroups.com
#31300: Add function-based virtual fields.
-------------------------------------+-------------------------------------
Reporter: Dulmandakh | Owner: Jeremy
| Nauta
Type: New feature | Status: closed

Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution: fixed

Keywords: field, database, | Triage Stage: Ready for
generated | checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"f333e3513e8bdf5ffeb6eeb63021c230082e6f95" f333e35]:
{{{
#!CommitTicketReference repository=""
revision="f333e3513e8bdf5ffeb6eeb63021c230082e6f95"
Fixed #31300 -- Added GeneratedField model field.

Thanks Adam Johnson and Paolo Melchiorre for reviews.

Co-Authored-By: Lily Foote <co...@lilyf.org>
Co-Authored-By: Mariusz Felisiak <felisiak...@gmail.com>
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31300#comment:19>

Django

unread,
Sep 20, 2023, 3:00:50 AM9/20/23
to django-...@googlegroups.com
#31300: Add function-based virtual fields.
-------------------------------------+-------------------------------------
Reporter: Dulmandakh | Owner: Jeremy
| Nauta
Type: New feature | Status: closed
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: field, database, | Triage Stage: Ready for
generated | checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by GitHub <noreply@…>):

In [changeset:"0b506bfe1ab9f1c38e439c77b3c3f81c8ac663ea" 0b506bf]:
{{{
#!CommitTicketReference repository=""
revision="0b506bfe1ab9f1c38e439c77b3c3f81c8ac663ea"
Refs #31300 -- Added example to GeneratedField release notes.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31300#comment:20>

Django

unread,
Sep 20, 2023, 3:02:09 AM9/20/23
to django-...@googlegroups.com
#31300: Add function-based virtual fields.
-------------------------------------+-------------------------------------
Reporter: Dulmandakh | Owner: Jeremy
| Nauta
Type: New feature | Status: closed
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: field, database, | Triage Stage: Ready for
generated | checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"7e4c1e8b3dd5806a17a617792a4fa0b763ef120d" 7e4c1e8]:
{{{
#!CommitTicketReference repository=""
revision="7e4c1e8b3dd5806a17a617792a4fa0b763ef120d"
[5.0.x] Refs #31300 -- Added example to GeneratedField release notes.

Backport of 0b506bfe1ab9f1c38e439c77b3c3f81c8ac663ea from main
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31300#comment:21>

Django

unread,
Nov 2, 2023, 10:48:23 AM11/2/23
to django-...@googlegroups.com
#31300: Add function-based virtual fields.
-------------------------------------+-------------------------------------
Reporter: Dulmandakh | Owner: Jeremy
| Nauta
Type: New feature | Status: closed
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: field, database, | Triage Stage: Ready for
generated | checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"208870b6122c4cbc39c3b2432e13db54c920db51" 208870b]:
{{{
#!CommitTicketReference repository=""
revision="208870b6122c4cbc39c3b2432e13db54c920db51"
Refs #31300 -- Allowed testing GeneratedField without collation.

CockroachDB and Snowflake don't support it.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31300#comment:22>

Django

unread,
Nov 2, 2023, 10:49:11 AM11/2/23
to django-...@googlegroups.com
#31300: Add function-based virtual fields.
-------------------------------------+-------------------------------------
Reporter: Dulmandakh | Owner: Jeremy
| Nauta
Type: New feature | Status: closed
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: field, database, | Triage Stage: Ready for
generated | checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"b735b90f439a964bda20a3ded19a39c5f0ce9b9a" b735b90]:
{{{
#!CommitTicketReference repository=""
revision="b735b90f439a964bda20a3ded19a39c5f0ce9b9a"
[5.0.x] Refs #31300 -- Allowed testing GeneratedField without collation.

CockroachDB and Snowflake don't support it.

Backport of 208870b6122c4cbc39c3b2432e13db54c920db51 from main
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31300#comment:23>

Reply all
Reply to author
Forward
0 new messages