[Django] #31609: Add support for Table Function Model

3 views
Skip to first unread message

Django

unread,
May 19, 2020, 6:59:28 AM5/19/20
to django-...@googlegroups.com
#31609: Add support for Table Function Model
-------------------------------------+-------------------------------------
Reporter: Petr | Owner: nobody
Přikryl |
Type: New | Status: new
feature |
Component: Database | Version:
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 |
-------------------------------------+-------------------------------------
Opening based on discussion here
https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!msg
/django-developers/3HC3twc_pGI/HWzlwAjoAQAJ

== Motivation
I have some complex database View with CTEs. The problem here is that I
need only few records from that View. But the View is always evaluated
completely and limited after that. The solution here is re-writing View as
Table Function https://stackoverflow.com/questions/11401749/pass-in-where-
parameters-to-postgresql-view.

== Proposed usage
{{{
class MyTableFunctionModel(Model)
parent = models.ForeignKey('self', on_delete=models.DO_NOTHING)

class Meta:
db_table = 'my_function'
table_function_args = [
TableFunctionArg(name='foo', required=False),
TableFunctionArg(name='bar', required=False),
]


MyTableFunctionModel.objects.table_function(foo=1, bar='value',
parent__foo=2, parent__bar='cha')

# SELECT ... FROM my_function(1, 'value') T1 JOIN my_function(2, 'cha') T2
ON T1.id = T2.parent_id
}}}

Here are some my working experiments
https://gist.github.com/petrprikryl/7cd765cd723c7df983de03706bf27d1a

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

Django

unread,
May 19, 2020, 7:00:19 AM5/19/20
to django-...@googlegroups.com
#31609: Add support for Table Function Model
-------------------------------------+-------------------------------------
Reporter: Petr Přikryl | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version:
(models, ORM) |
Severity: Normal | Resolution:
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/31609#comment:1>

Django

unread,
May 19, 2020, 8:33:33 AM5/19/20
to django-...@googlegroups.com
#31609: Add support for Table Function Model
-------------------------------------+-------------------------------------
Reporter: Petr Přikryl | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version:
(models, ORM) |
Severity: Normal | Resolution:
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 Ahmad A. Hussein):

* cc: Ahmad A. Hussein (added)


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

Reply all
Reply to author
Forward
0 new messages