dbTalk Databases Forums  

Array interface

comp.databases.postgresql comp.databases.postgresql


Discuss Array interface in the comp.databases.postgresql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Mladen Gogala
 
Posts: n/a

Default Array interface - 11-03-2010 , 08:54 AM






I wrote a little Perl script, intended to test the difference that array
insert makes with PostgreSQL. Imagine my surprise when a single record
insert into a local database was faster than batches of 100 records.
Here are the two respective routines:

sub do_ssql
{
my $exec_cnt = 0;
while (<FL>)
{
chomp;
my @row = split /$sep/;
$sth->execute(@row);
$exec_cnt++;
}
$dbh->commit();
print "Insert executed $exec_cnt times.\n";
}

sub do_msql
{
my $bsz = shift;
die("Batch size must be >0!\n") unless $bsz > 0;
my $exec_cnt = 0;
my @tstat;
my (@col1, @col2, @col3);
while (<FL>)
{
chomp;
my @row = split /$sep/;
push @col1, $row[0];
push @col2, $row[1];
push @col3, $row[2];
if ($. % $bsz == 0)
{
my $tuples = $sth->execute_array({ArrayTupleStatus =>
\@tstat},
\@col1, \@col2, \@col3);
die("Multiple insert failed!\n") if (!$tuples);
@col1 = ();
@col2 = ();
@col3 = ();
$exec_cnt++;
}

}
if ($#col1 >= 0)
{
my $tuples = $sth->execute_array({ArrayTupleStatus => \@tstat},
\@col1, \@col2, \@col3);
die("Multiple insert failed!\n") if (!$tuples);
$exec_cnt++;
}
$dbh->commit();
print "Insert executed $exec_cnt times.\n";
}


The variable "$sth" is a prepared "INSERT" statement handle. Is that a
quirk of DBD::Pg or array bind doesn't do me any good with PostgreSQL?




--
http://mgogala.byethost5.com

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.