Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Creating Table and Inserting Data from CSV

by sk (Curate)
on Oct 04, 2005 at 19:14 UTC ( #497366=note: print w/ replies, xml ) Need Help??


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


Comment on Re: Creating Table and Inserting Data from CSV
Download Code
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.
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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://497366]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (14)
As of 2015-07-07 15:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (90 votes), past polls