Giter Site home page Giter Site logo

Comments (4)

millerdev avatar millerdev commented on July 22, 2024

It looks like the given example can be done without a CTE

(
    Purchase.objects
    .filter(...)
    .aggregate(total_thing=Sum("thing"))
)

However, it's hard to tell since I cannot see the query constructed by get_purchases(profile, start_date, end_date). Can you provide more detail to show why you need to use a CTE?

from django-cte.

warmwaffles avatar warmwaffles commented on July 22, 2024

It looks like the given example can be done without a CTE

I was trying to do a contrived example as short as possible to try and get the point across.

So, the reason I use a CTE is to avoid a nasty nested query and provide postgres a better hint as to what indexes to use.

I have some more complex tables I have to join into a CTE then do an aggregate on. Django's aggregate does not provide a clean way for me to filter on the annotations and then inspect the query for an explain analyze.

I can't really paste the exact code in here as it is a few hundred lines and my employer would not be too happy 😛

from django-cte.

warmwaffles avatar warmwaffles commented on July 22, 2024

I did find it useful that the join method exposes _join_type was very useful for a LOUTER join.

from django-cte.

millerdev avatar millerdev commented on July 22, 2024

I think the problem is that there is no way (with the Django ORM) to add the CTE to the FROM clause except with a JOIN. Feel free to re-open this issue if you can come up with a simplified example that has enough moving parts to replicate the issue. Preferably, make the example using the test models.

from django-cte.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.