Re: Leveraging the ORM for very complex queries

2015-05-17 Thread Suriya Subramanian
Thank you Russ and Michael. For the reference of other users and to get feedback, here's what I ended up doing: https://gist.github.com/anonymous/154512b369fe7e273631 import itertools from django.db import connection """ Combine SQL and ORM. sql = 'SELECT * FROM ( {} ) T1 NATURAL FULL OUTER

Re: Leveraging the ORM for very complex queries

2015-05-04 Thread Michael Manfre
The internals of the ORM are deemed a private API and have undergone significant changes in the past without being constrained by the two release deprecation cycle. As some one who was forced to write query construction code based upon Django internals, my recommendation is to only do that if

Re: Leveraging the ORM for very complex queries

2015-05-04 Thread Suriya Subramanian
Hi Russ, Thank you for your answer. I am aware of raw. However, that's now what I am looking for. Let me give a few examples of queries that I would like to write: 1) Window functions over an ORM query: SELECT "date", SUM("weight__sum") OVER (ORDER BY "date") FROM (

Re: Leveraging the ORM for very complex queries

2015-05-03 Thread Russell Keith-Magee
Hi Suriya, It sounds like you're looking for raw SQL queries: https://docs.djangoproject.com/en/1.8/topics/db/sql/#performing-raw-queries This allows you to issue a SQL query in SQL, rather than trying to bend the ORM to meet some complex query requirement. You can't compose a raw query like a

Leveraging the ORM for very complex queries

2015-05-02 Thread Suriya Subramanian
Hello, I have to write some complex SQL queries that I am unable to express using the ORM. I construct these complex queries by writing a few simple ORM queries, getting the SQL using QuerySet.query and combining them with various SQL operators manually. These hand-crafted queries are not very