Opened 3 years ago

Last modified 2 months ago

#31300 assigned New feature

Add function-based virtual fields.

Reported by: Dulmandakh Owned by: Jeremy Nauta
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords:
Cc: Petr Přikryl, elonzh Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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.

Change History (8)

comment:1 Changed 3 years ago by Mariusz Felisiak

Resolution: wontfix
Status: newclosed
Summary: Add Generated Columns (PostgreSQL) supportAdd function-based virtual fields on PostgreSQL and Oracle.

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.

comment:2 Changed 2 years ago by Petr Přikryl

Cc: Petr Přikryl added

comment:3 Changed 5 months ago by Mariusz Felisiak

Resolution: wontfix
Status: closednew
Summary: Add function-based virtual fields on PostgreSQL and Oracle.Add function-based virtual fields.
Triage Stage: UnreviewedAccepted

Tentatively accepted, based on the feedback from the mailing list.

comment:4 Changed 5 months ago by Mariusz Felisiak

Has patch: set
Owner: changed from nobody to Jeremy Nauta
Patch needs improvement: set
Status: newassigned

comment:5 Changed 5 months ago by elonzh

Cc: elonzh added

comment:6 Changed 2 months ago by Paolo Melchiorre

Patch needs improvement: unset

comment:7 Changed 2 months ago by Mariusz Felisiak

Patch needs improvement: set

comment:8 Changed 2 months ago by Jeremy Nauta

Patch needs improvement: unset
Note: See TracTickets for help on using tickets.
Back to Top