in reply to Batch Upload/Insert – Row wise with Perl DBI
The big performance hit is not in the execute() method itself, but in all of the "housekeeping" that the DB does to finalize the transaction. When you connected, the default would have been to set autocommit=1, that causes each execute() to be an independent transaction. You can temporarily override the autocommit, by explicitly starting a transaction as show below. Assuming that you have set RaiseError=1,:
my @data = ([11,12,13], [21,22,23], [31,32,33]); $sth = $dbh->prepare("insert into table values (?, ?, ?)"); # start new transaction # $dbh->begin_work(); #or perhaps $dbh->do("BEGIN"); foreach my $row (@data) { $sth->execute(@$row); } # end the transaction # $dbh->commit(); #or perhaps $dbh->do("COMMIT");
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Batch Upload/Insert – Row wise with Perl DBI
by APerlPro (Initiate) on Mar 22, 2012 at 23:11 UTC | |
by Marshall (Canon) on Mar 23, 2012 at 01:45 UTC |