[Django] #30369: Creating database tables from queries based on ORM API

10 views
Skip to first unread message

Django

unread,
Apr 15, 2019, 4:30:22 AM4/15/19
to django-...@googlegroups.com
#30369: Creating database tables from queries based on ORM API
-------------------------------------+-------------------------------------
Reporter: elfring | Owner: nobody
Type: New | Status: new
feature |
Component: Database | Version: 2.2
layer (models, ORM) | Keywords: database tables,
Severity: Normal | queries, ORM, API, SQL, storage
| management, object-relational
Triage Stage: | mapping, computation results, CTAS
Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Value combinations can be counted in records also together with the
software “Django 2.2” by
[https://docs.djangoproject.com/en/2.2/ref/databases/ database services].
I am looking for ways to store a computation result into a dynamically
generated table.
* How should such table creation be achieved by the programming interface
“object-relational mapping”?
* Would you like to support
[https://en.wikipedia.org/wiki/Data_definition_language#CREATE_TABLE_statement
the SQL command “CREATE TABLE AS SELECT” (CTAS)]?

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

Django

unread,
Apr 23, 2019, 8:18:04 AM4/23/19
to django-...@googlegroups.com
#30369: Creating database tables from queries based on ORM API
-------------------------------------+-------------------------------------
Reporter: Markus Elfring | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: database tables, | Triage Stage:
queries, ORM, API, SQL, storage | Unreviewed
management, object-relational |
mapping, computation results, |
CTAS |

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

* version: 2.2 => master


Comment:

I don't think that we will support `CREATE TABLE AS SELECT`. In your use
case I would create `MATERIALIZED VIEW` (or `VIEW`) in a migrations with
raw SQL. Such views can be introspected automatically (see
[https://docs.djangoproject.com/en/2.2/ref/django-admin/#database-
specific-notes inspectdb]) and used via Django ORM (see
[https://docs.djangoproject.com/en/2.2/ref/models/options/#django.db.models.Options.managed
managed option]).

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

Django

unread,
Apr 23, 2019, 3:21:34 PM4/23/19
to django-...@googlegroups.com
#30369: Creating database tables from queries based on ORM API
-------------------------------------+-------------------------------------
Reporter: Markus Elfring | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: database tables, | Triage Stage:
queries, ORM, API, SQL, storage | Unreviewed
management, object-relational |
mapping, computation results, |
CTAS |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Markus Elfring):

Replying to [comment:1 felixxm]:
* Does the functionality “materialized view” provide run time
characteristics which are similar to the CTAS command?
* Does it belong to the SQL standard?
* The support for it varied between databases over time. How will the
software evolve further in this area?

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

Django

unread,
Apr 24, 2019, 1:02:24 AM4/24/19
to django-...@googlegroups.com
#30369: Creating database tables from queries based on ORM API
-------------------------------------+-------------------------------------
Reporter: Markus Elfring | Owner: nobody
Type: New feature | Status: closed

Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: wontfix

Keywords: database tables, | Triage Stage:
queries, ORM, API, SQL, storage | Unreviewed
management, object-relational |
mapping, computation results, |
CTAS |
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:

> * Does the functionality “materialized view” provide run time
characteristics which are similar to the CTAS command?

Yes it is quite similar, db will recognize column types.

> * Does it belong to the SQL standard?

I'm not sure, but I don't think so.

> * The support for it varied between databases over time.

Materialized views are supported on PostgreSQL and Oracle.

> * How will the software evolve further in this area?

Do you mean by databases? I don't know answer for such existential
question :)

Please use one of
[https://code.djangoproject.com/wiki/TicketClosingReasons/UseSupportChannels
support channels] if you have other support questions related with Django.
If you have questions about databases you should probably ask somewhere
else e.g. on StackOverflow.

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

Django

unread,
Apr 24, 2019, 4:18:45 AM4/24/19
to django-...@googlegroups.com
#30369: Creating database tables from queries based on ORM API
-------------------------------------+-------------------------------------
Reporter: Markus Elfring | Owner: nobody
Type: New feature | Status: new

Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: database tables, | Triage Stage:
queries, ORM, API, SQL, storage | Unreviewed
management, object-relational |
mapping, computation results, |
CTAS |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Markus Elfring):

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


Comment:

Replying to [comment:3 felixxm]:


> I'm not sure, but I don't think so.

I would find the support for the SQL standard statement “CREATE TABLE AS
SELECT” (CTAS) nicer (while working with materialized views can be
similarly useful).

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

Django

unread,
Apr 24, 2019, 4:43:22 AM4/24/19
to django-...@googlegroups.com
#30369: Creating database tables from queries based on ORM API
-------------------------------------+-------------------------------------
Reporter: Markus Elfring | Owner: nobody
Type: New feature | Status: closed

Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: wontfix

Keywords: database tables, | Triage Stage:
queries, ORM, API, SQL, storage | Unreviewed
management, object-relational |
mapping, computation results, |
CTAS |
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:

Please start a new thread on
[https://groups.google.com/forum/?utm_source=digest&utm_medium=email#!forum
/django-developers `django-developers`] if you really think that support
for `CREATE TABLE AS SELECT` should be added to the Django ORM. IMO use
case is really narrow because even if you will create such table in ORM it
will be tricky to make it accessible via ORM.

We can reopen this ticket if we reach consensus on `django-developers`.

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

Reply all
Reply to author
Forward
0 new messages