MySQL temp table, what's the benefit?

So this is a MySQL question rather than a Xojo question but it is part of a Xojo app. I’m working on a project where I get csv files with a variable number of columns. The first row is always a header row with field names. So I create a temp table with the column names from the header row and then readline through the rest of the file and insert the data. I do have a primary key that is the line counter. After that I build a permanent table and do an INSERT with a SELECT *.

I’m not sure why I’m doing the temp table step? Other than it seemed to be what I was reading was a way to do it. Why not just build the permanent table and insert the data into that? Skip the temp table altogether.

What prompted you to follow this path in the first place?

[quote=305738:@Duane Mitchell]
I’m not sure why I’m doing the temp table step? Other than it seemed to be what I was reading was a way to do it. Why not just build the permanent table and insert the data into that? Skip the temp table altogether.[/quote]

Temp tables are PER USER so if you have 3 users doing imports at the same time they each have their own version of that temp table
If you use a single permanent table then you have 1 table and have to create that table & import process in a way that you have to handle the possibility of multiple users doing an import at the same time
Additionally since you needed a way to handle an arbitrary table (unknown number of columns) you’d have to grant users the permissions to create tables (and you cant say “oh just allow them to create ONE table”) You can however make it so users can create temporary tables and NOT create any other kinds of tables

Duane wanted a way to import and arbitrary csv file into a table using prepared statements

https://forum.xojo.com/37227-mysqlprepared-compile-error/p1#p304809

I asked because he said this…

You should edit that so it shows Duane asked it not me :slight_smile:

Thanks Norman. I would have crashed into those reasons once I created the user accounts for this. That saves me some work or rework.