Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9031395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:43:19+00:00 2026-06-16T07:43:19+00:00

This is my first Stack Overflow post! The community has been a great help!

  • 0

This is my first Stack Overflow post! The community has been a great help!

I’ve got a 90K row CSV I’m trying to insert into a table, via a temp table with CSV like:

CREATE TEMPORARY TABLE temp_product like product;
LOAD DATA LOCAL INFILE "myfile.csv"
...

But I am trying to wrap up the insert and a few additional operations via a procedure, which contains a transaction, and an exit handler incase anything fails, or throws a warning:

CREATE PROCEDURE update_products ()
BEGIN
    DECLARE EXIT HANDLER FOR SQLEXCEPTION, NOT FOUND, SQLWARNING ROLLBACK;
    START TRANSACTION;
    ....

I like this approach because it allows me to automatically rollback if any errors are encountered, and also wraps up the whole logical chunk of transactions nicely. Alas:

Error : LOAD DATA is not allowed in stored procedures

(I’m not certain why this is? I guess it’s just not supported yet?) I’m not certain I have the syntax correct (or if this is even possible) but I would even be OK with something like:

DECLARE EXIT HANDLER FOR SQLEXCEPTION, NOT FOUND, SQLWARNING ROLLBACK;
START TRANSACTION;

But that throws the obvious syntax error:

Error : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DECLARE EXIT HANDLER FOR SQLEXCEPTION, NOT FOUND, SQLWARNING ROLLBACK' at line 1

It seems I could make this work if I could load the CSV in a different manner, but I’d likely lose the speed of doing the inserts in bulk, and/or have to use a disk-based table as I would likely need to make multiple connections to it. As far as I understand, a temporary table exists only for the single connection/transaction, and I’m not 100% certain how my MySQL client, navicat, manages this.

I’m also not against wrapping this all in PHP if that’s the most sane way to manage a script that has automatic rollback upon error/warning in transactions with LOAD DATA.

Feel free to tell me I am approaching this totally wrong as well. I feel like there’s probably a much smarter way to do what I’m doing.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T07:43:21+00:00Added an answer on June 16, 2026 at 7:43 am

    Unfortunately there is no support for LOAD DATA INFILE in stored procedures. I do recall once seeing a workaround hack where someone used MySQL stored procedure to call a shell script to actually perform the upload, but that seems like a potentially problematic solution, security-wise. You might be able to Google it this solution.

    The best bet would probably be to use some sort of script (PHP, shell, etc.) to perform the load into the temporary table and then call the stored procedure to actually populate into the permanent table. I would think that as long as you had transactional support for this piece, you can roll back the part that really matters (populating the permanent table).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first post on Stack Overflow. I am trying to build a
Hello everyone this is my first post on stack overflow.com I am trying to
ALL, This is my first post on Stack Overflow. I have been programming in
This is my first post to stack overflow. I've been lurking this site for
First of all, this is my first post in Stack Overflow and I'm trying
This is my first post on stack overflow. I've got a show/hide with a
Ok this is my first post on Stack Overflow I have been reading for
this is my first ever post to Stack Overflow and it's because I've been
This is my first post on Stack Overflow and I'm just wondering on the
I have been reading this blog post and this stack overflow post but I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.