﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
28919	Add support for Common Table Expression (CTE) queries	Daniel Miller	Genaro Camele	"[http://django-cte-trees.readthedocs.io/en/latest/ django-cte-trees] (also [https://github.com/matthiask/django-cte-forest django-cte-forest]) provides specialized uses of CTE queries for managing hierarchical data with recursive queries. To accomplish this, it uses the `QuerySet.extra()` API. This is my specific use case for CTE queries at the moment, however it leverages only one small part of what is possible with CTE queries: [https://www.postgresql.org/docs/9.6/static/queries-with.html PostgreSQL], [https://dev.mysql.com/doc/refman/8.0/en/with.html MySQL], [https://docs.microsoft.com/en-us/sql/t-sql/queries/with-common-table-expression-transact-sql SQL Server].

Another implementation supporting more general uses of CTE queries was [https://groups.google.com/forum/#!topic/django-developers/b370mxfKCHg presented on the developers mailing list], although I'm not sure it has ever made it any further than that. The code can be found [https://github.com/django/django/compare/master...ashleywaite:cte-dev on github]. It appears to do its magic by mutating `base_query.extra_tables`, which seems to be a private/internal part of the ORM.
"	New feature	assigned	Database layer (models, ORM)	dev	Normal		QuerySet.extra	Matthew Pava Tyson Clugg Matthew Schinckel Ole Laursen Ian Foote Carlton Gibson TZanke Keryn Knight Tim Schilling Ryan Hiebert Markus Zapke-Gründemann Hannes Ljungberg Krzysztof Jagiełło Jameel A. Paolo Melchiorre Krzysztof Szularz Marko G. John Speno Julien Palard Dave Johansen Peter Lithammer Fabio Caritas Barrionuevo da Luz Sébastien Corbin Eron Lloyd Peter Thomassen Tom Carrick Dmytro Litvinov şuayip üzülmez Carsten Fuchs Alexander Nestorov Ahmed Ibrahim Florian Demmer JaeHyuckSa	Accepted	0	0	0	0	0	0
