Is there a way to see the raw SQL executed by a bulk_create on django?

772 views Asked by At

I'm using Django's ORM to insert thousands of objects in a Postgre's DB. And it works fine, but sometimes one of those registers have a wrong format and the insert operation doesn't work.

I can't do this kind of insert ignoring errors so I'd like to see the SQL executed by the operation and the bulk_insert only returns a list of the objects.

1

There are 1 answers

0
Wouter Klein Heerenbrink On BEST ANSWER

When in debug-mode you could use the django.db.backends logger. https://docs.djangoproject.com/en/1.8/topics/logging/#django-db-backends

In production I would use loggers for PostGres itself, because saving these queries from within a Django process will (probably) have major impact on your performance.