Sunday, February 26, 2017

Re: group by 3 fields

On Sun, Feb 26, 2017 at 5:05 PM, <marcin.j.nowak@gmail.com> wrote:
>
>
> On Sunday, February 26, 2017 at 12:55:17 PM UTC+1, Daniel Roseman wrote:
>>
>>
>> You should explain what you want to achieve. Grouping is pointless on its
>> own. In any case, when working with an ORM like Django's it is generally not
>> helpful to think in terms of SQL.
>> --
>> DR.
>
>
> Also forget window functions, triggers, conditionals, pubsub and many other
> great db features, just because of Django ORM...
>
> Daniel is right - Django ORM will limit your expressions, but not every ORM
> works that way. SQLAlchemy, in contrast, allows you not only grouping, but
> also wrap anything into their expression API.
>
> With Django there is still possibility to do raw queries, nby
> Model.objects.raw(). I'm doing a complex queries that way, but I'm avoiding
> spaghetti code by using django-sqltemplate. It allows you to write big SQLs
> in separate files (also as templates),load using Django templates engine,
> and finally pass the result directly to Model.objects.raw(), if you want.
>
> You can force grouping, AFAIR. Try to get query object from your queryset,
> i.e. q=Model.objects.all().query and play with q.group_by or something like
> that. But this is kind of nasty workaround. I would not recommend doing
> grouping that way in a project with long-term support.
>
> Generally speaking Django ORM is quite simple, limited and does not work
> well for more complex projects. I don't want to talk more about this,
> because my point of view is generally opposite to the "Django Way" (tm). I
> can just say that I'm using Django ORM as simple mapper for most typical
> cases, leaving more complex things for better tools.
>
> And, Larry, please never give up and always think about db and data first,
> then about application layer. Data is most important. It's lifetime is much
> longer than any app. Continue thinking about grouping, windowing, indexing,
> fts and so on, and find a way how to handle such things using tools like
> Django.

I agree with Marcin. The ORM is a tool and the tool should serve its
user, not the other way around. I have an app that has been developed
and deployed over 7 years. At the beginning it only used the ORM. But
over time, due to performance issues, and application requirements,
we've had to move to raw SQL more and more.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CACwCsY66HhECopa0xOHYJ3n_t-17-OZ7dfTFWOvB7BUK_3_Zmw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment