Browse files

adding a raw sql method

  • Loading branch information...
1 parent 3aa06e8 commit a5ec7bb90b1882db95c6f4eae94ea373f7f6a50f @coleifer committed Oct 12, 2012
Showing with 4 additions and 0 deletions.
  1. +4 −0
@@ -2089,3 +2089,7 @@ def dfs(model):
for m in sorted(models, key=names, reverse=True):
return list(reversed(ordering)) # want parents first in output ordering
+def raw_sql(query):
+ db = query.model_class._meta.database
+ return query.sql(db.get_compiler())

3 comments on commit a5ec7bb


Can someone please give an example of how to use this helper function?


query =
print raw_sql(query)


Because this page is one of first Google's results on the topic, I'll leave it here.
Here is how we can determine exact SQL produced by query, with all parameters substituted.
This works for PostgreSQL, but not sure about other database types.

query ='value', fields2<
Please sign in to comment.