On Wed, Dec 31, 2008 at 5:11 AM, Info Cascade <informationcasc...@gmail.com> wrote: > > Hi -- > > I am getting intermittent errors on certain database queries on our > production server. > I am having a hard time duplicating them (most of the time they run > okay, only sometimes on the production server am I receiving exception > messages), > so I want to log the SQL query itself and see what it is, and why it > might be failing. > Is there some way of seeing what SQL statement will be executed by a > QuerySet before actually executing it?
Yes. If you have the query: >>> Author.objects.filter(...) then the following: >>> print Author.objects.filter(...).query.as_sql() will print the SQL that results from the query. Another approach is to inspect the query log. If debug is enabled in your settings, then: >>> from django.db import connection >>> connection.queries will print a list of all queries that have been passed to the database. Yours, Russ Magee %-) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---