2

When calling bulk_create() using django-pyodbc backend, an insert statement is run for each object in the batch. The behavior should be to run a single insert statement per batch.

Is this a bug, or is there a way to alter this behavior?

Versions:

  • django==1.7
  • pyodbc==3.0.10
  • django-pyodbc==1.0.1
  • FreeTDS v1.00.21
  • unixODBC v2.3.4
aensm
  • 3,325
  • 9
  • 34
  • 44
  • Which `django-pyodbc` are you using? There are quite a few out there. I've found the most actively maintained and feature complete is `django-pyodbc-azure`, which works for SQL Server *or* Azure. I use it with on-premise SQL Server 2008 through 2014. – FlipperPA Dec 07 '16 at 19:54

1 Answers1

1

I'm betting the version of django-pyodbc you're using doesn't support bulk insert. I would recommend using django-pyodbc-azure, which you can install with:

pip install django-pyodbc-azure<1.8

django-pyodbc-azure matches it's version numbers to Django's, so you'll want the latest / greatest version from the 1.7 branch (thus, <1.8).

It should support bulk_insert():

https://github.com/michiya/django-pyodbc-azure/blob/adc5d88a9928cecc0e9d33aacca301e0084ff824/sql_server/pyodbc/features.py#L15

I'd also recommend upgrading to Django 1.8 (long term support) or 1.10 (current release), as security patches and bug fixes are no longer being issued for 1.7. Good luck!

FlipperPA
  • 13,607
  • 4
  • 39
  • 71
  • 1
    Thanks, I'm testing this this out now. Will post again in a few minutes. – aensm Dec 07 '16 at 20:37
  • `django-pyodbc-azure` does support `bulk_insert` and passes my other tests too. Seems to be working better than the other fork of `django-pyodbc` – aensm Dec 08 '16 at 19:26