Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^3: Inserting CSV Into DB w/o CSV Modules

by tachyon (Chancellor)
on Nov 24, 2004 at 00:21 UTC ( [id://410029]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Inserting CSV Into DB w/o CSV Modules
in thread Inserting CSV Into DB w/o CSV Modules

while(my $line = <INFILE> ) { $csv->parse($line); my ( $state,$city,$location ) = $csv->fields(); # assumming these + are col1,col2,col3 $sth->execute($state,$city,$location) or die "Couldn't execute que +ry: $dbh->errstr"; }

This will be slow. It would be a lot faster to do:

my $sql =<<SQL; LOAD DATA LOCAL INFILE '$infile' INTO TABLE tbl_name FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' SQL $dbh->do($sql);

See LOAD DATA

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2024-04-25 07:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found