#179 open
Psycopg website

Mogrify performance on arrays

Reported by Psycopg website | August 28th, 2013 @ 02:18 PM

Submitted by: ChrisB

If I run cursor.mogrify on a 64000 double array it is taking 350ms. If I just do a 'ARRAY[' + ','.join(map(str, array)) + ']' and put it into a string format myself it only takes 55ms. Although the documentation tells you not to do this, it is bringing the insert time of my app down massively.

Comments and changes to this ticket

  • Daniele Varrazzo

    Daniele Varrazzo September 20th, 2013 @ 11:28 AM

    • State changed from “new” to “invalid”

    Thank you for inventing the SQL injection.

    Of course feel free to do it in your app if you know where the input is coming from, but don't even think to suggest it as a good idea.

  • Federico Di Gregorio

    Federico Di Gregorio September 20th, 2013 @ 12:35 PM

    • State changed from “invalid” to “open”
    • Tag cleared.
    • Assigned user set to “Federico Di Gregorio”

    Daniele, wait. He was talking about a simple benchmark and I can see where the bottleneck is. The mogrification of arrays is slow, because the arguments are checked one by one: we can probably make this faster by caching the adapter when the list is know to contain only objects of the same type. I'll investigate this.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Psycopg is the most used PostgreSQL adapter for the Python programming language. At the core it fully implements the Python DB API 2.0 specifications. Several extensions allow access to many of the features offered by PostgreSQL.

Shared Ticket Bins