Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Creating Table and Inserting Data from CSV

by sk (Curate)
on Oct 04, 2005 at 19:14 UTC ( [id://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

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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2024-04-20 05:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found