To clarify my question I would like to know if it is possible to idiomatically use the Django ORM whilst accessing CTE features. I imagine I could use CTE by writing raw SQL statements but the ability to use the ORM 'syntactic sugar' to bypass hand coding SQL statements was one of the original appeals of Django.
为了澄清我的问题,我想知道是否可以在访问CTE功能时习惯性地使用Django ORM。我想我可以通过编写原始SQL语句来使用CTE,但是使用ORM'语法糖'绕过手工编码SQL语句的能力是Django最初的吸引力之一。
1 个解决方案
#1
7
Django doesn't support CTEs directly as these are not common to all databases (MySQL doesn't support it). There are packages that extend the capability of Django's ORM to support CTEs. One of these is django-cte-trees. Note that it only supports PostgreSQL.
Django不直接支持CTE,因为这些并不是所有数据库共有的(MySQL不支持它)。有些软件包可以扩展Django ORM的功能以支持CTE。其中之一是django-cte-trees。请注意,它仅支持PostgreSQL。
#1
7
Django doesn't support CTEs directly as these are not common to all databases (MySQL doesn't support it). There are packages that extend the capability of Django's ORM to support CTEs. One of these is django-cte-trees. Note that it only supports PostgreSQL.
Django不直接支持CTE,因为这些并不是所有数据库共有的(MySQL不支持它)。有些软件包可以扩展Django ORM的功能以支持CTE。其中之一是django-cte-trees。请注意,它仅支持PostgreSQL。