|
|
|
|
|
by jiaaro
841 days ago
|
|
If you use postgres, psycopg provides `cursor.mogrify(query, params)` which returns the actual query that will be executed . For example: cursor.mogrify(*queryset.query.sql_with_params())
Alternatively, you can set the log level of the `django.db.backends` logger to DEBUG to see all executed queries |
|
> Django gives you two ways of performing raw SQL queries: you can use `Manager.raw()` to perform raw queries and return model instances, or you can avoid the model layer entirely and execute custom SQL directly.
https://stackoverflow.com/questions/1074212/how-can-i-see-th... has :
And: But that's still not backend-specific SQL?There should be an interface method for this. Why does psycopg call it mogrify?
https://django-debug-toolbar.readthedocs.io/en/latest/panels... :
> debug_toolbar.panels.sql.SQLPanel: SQL queries including time to execute and links to EXPLAIN each query
But debug toolbars mostly don't work with APIs.
https://github.com/django-query-profiler/django-query-profil... :
> Django query profiler - one profiler to rule them all. Shows queries, detects N+1 and gives recommendations on how to resolve them
https://github.com/jazzband/django-silk :
> Silk is a live profiling and inspection tool for the Django framework. Silk intercepts and stores HTTP requests and database queries before presenting them in a user interface for further inspection