insert-on-duplicate-key
insert-on-duplicate-key copied to clipboard
SQLSTATE[HY000]: General error: 1390 Prepared statement contains too many placeholders
Hey @yadakhov I guess I pushed too hard insert-on-duplicate-key
, cause apparently I hit the limit of MySQL. 😅
I'm just posting this here mainly for maybe somebody else who could get carried away with fast bulk insert/updates like me.
I tried to insert ~5,800 rows of 32 columns at once and I got the above error. It seems it's due to the place holders limit of MySQL.
Don't know if you want to, but basically I believe it's possible to fix this limiting the length of the inline $data
array generating the SQL statement. You could split the array and iterate through it in slots of less than ~65,000 placeholders, or maybe simply raise an Exception
for "too much data". It seems in fact Eloquent (v5.5
in my case) somehow fails to raise an appropriate Exception
and keeps trying forever.
BTW I fixed the issue limiting my data to ~2,000 rows and it works great, super fast! 🚀
Thanks for submitting your error.
I will add an exception telling users to array chunks their large array if it is over the mysql placeholder limits of 65,535.
SQLSTATE[HY000]: General error: 1390 Prepared statement contains too many placeholders
Help me to Solve this please
You can break your data into smaller chunks. Something like:
// break data into max size of 200
$chunks = array_chunk($data, 200);
foreach ($chunks as $chunk) {
// Do insert here
}
Thanks
On Wed, Dec 12, 2018 at 11:35 PM Yada Khov [email protected] wrote:
You can break your data into smaller chunks. Something like:
// break data into max size of 200 $chunks = array_chunk($data, 200);
foreach ($chunks as $chunk) { // Do insert here }
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/yadakhov/insert-on-duplicate-key/issues/18#issuecomment-446685102, or mute the thread https://github.com/notifications/unsubscribe-auth/AYis9TUoGMxqagol9nz3Bb38KfNtx42Cks5u4UWDgaJpZM4QQcmC .
-- https://about.me/salman_salu?promo=email_sig&utm_source=product&utm_medium=email_sig&utm_campaign=gmail_api SalMan S about.me/salman_salu https://about.me/salman_salu?promo=email_sig&utm_source=product&utm_medium=email_sig&utm_campaign=gmail_api