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.
* 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>
* cc: Petr Přikryl (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/31300#comment:2>
* 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>
* 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>
* cc: elonzh (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/31300#comment:5>
* needs_better_patch: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/31300#comment:6>
* needs_better_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/31300#comment:7>
* needs_better_patch: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/31300#comment:8>
* cc: Lily Foote (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/31300#comment:9>
* cc: Paolo Melchiorre (added)
* keywords: => field, database, generated
--
Ticket URL: <https://code.djangoproject.com/ticket/31300#comment:10>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/31300#comment:11>
* 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>
* 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>
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>
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>
* cc: jul...@pinabausch.org (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/31300#comment:16>
* needs_better_patch: 0 => 1
* stage: Ready for checkin => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/31300#comment:17>
* needs_better_patch: 1 => 0
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/31300#comment:18>
* 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>
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>
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>
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>
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>