http://www.perlmonks.org?node_id=497366


in reply to Creating Table and Inserting Data from CSV

Thanks xorl! Sorry awolhd, I should have read it carefully.

NOTE: non-Perl solution

Wouldn't this do?

mysql> LOAD DATA INFILE 'data.csv' FIELDS TERMINATED BY ',' INTO TABLE + MYTABLE;

you need to drop your previous table

-SK

Replies are listed 'Best First'.
Re^2: Creating Table and Inserting Data from CSV
by xorl (Deacon) on Oct 04, 2005 at 19:22 UTC

    That would work fine if the table alreay existed. I think he wants to create a table first. In which case you somehow have to figure out the create table statement first. Once the table is created, like I said above, we both agree he should use load data infile

    I'd like to know exactly what he is doing. It seems odd that he'd have a csv file where the column order and column names changes randomly.

      It is odd, but I'm taking a dump of settings that change regularly with new software loads.
Re^2: Creating Table and Inserting Data from CSV
by awohld (Hermit) on Oct 04, 2005 at 19:19 UTC
    When I try that it says the table doesn't exist, I want the program to create the table every time. As far as my understanding you need an existing table to do LOAD DATA INFILE.