Largest possible size for executemany() in PEP-249 (Database API)

Neil Hodgson nhodgson at iinet.net.au
Thu Feb 28 23:26:05 CET 2013


Roy Smith:

> _mysql_exceptions.OperationalError: (1153, "Got a packet bigger than
> 'max_allowed_packet' bytes")
>
> Is there any way (other than trial and error) to know how many records
> I can pass in one call before I blow up?

    Its unlikely to be a limit in the number of records but a limit on 
the number of bytes in the serialized command stream. With a deep 
understanding of the format you could count bytes until about to go over 
and then flush. I'd *guess* that the data is being sent as textual SQL 
INSERT statements so you could work out what your insertions look like 
as INSERT statements and see how many fit into max_allowed_packet. 
max_allowed_packet is probably 1 million so looking like 100 bytes per 
INSERT but will depend on data as inserting "Ko" should use less bytes 
than inserting "Naragarajan".

    Neil



More information about the Python-list mailing list