【发布时间】:2019-05-18 03:00:53
【问题描述】:
Perl 的DBD::Pg PostgreSQL 绑定将始终获取查询的整个结果集。因此,如果您使用简单的准备执行来遍历一个大表,您只需运行$sth->execute() 就可以将整个表保存在内存中。准备好的语句和像fetch_row 这样的调用没有帮助。
如果您使用的是 BIG 表,以下操作将会失败。
use DBI;
my $dbh = DBI->connect("dbi:Pg:dbname=big_db","user","password",{
AutoCommit => 0,
ReadOnly => 1,
PrintError => 1,
RaiseError => 1,
});
my $sth = $dbh->prepare('SELECT * FROM big_table');
$sth->execute(); #prepare to run out of memory here
while (my $row = $sth->fetchrow_hashref('NAME_lc')){
# do something with the $row hash
}
$dbh->disconnect();
【问题讨论】:
标签: postgresql perl large-data dbi database-cursor