【发布时间】:2011-11-27 14:01:54
【问题描述】:
我最近将一个 Perl 应用程序表单 Oracle 移植到 Postgres(我第一次使用 Postgres),我被一个小问题难住了,我可以将其简化为以下示例代码:
use strict;
use warnings;
use DBI;
my @db_params = qw (dbi:Pg:host=127.0.0.1;database=test test test);
my $dbh = DBI->connect(@db_params, {AutoCommit => 0 } ) or die ;
while (1) {
my $sth = $dbh->prepare_cached('SELECT localtimestamp ') or die;
$sth->execute() or die;
my $result = $sth->fetchall_arrayref();
print $result->[0][0] , "\n";
sleep(5);
}
这个输出:
2011-11-27 16:46:25.94291
2011-11-27 16:46:25.94291
2011-11-27 16:46:25.94291
除非我断开连接并重新连接到数据库,否则我一直得到相同的时间戳。
如何确保每次从数据库中选择 localtimestamp 时,我得到的值与执行 sql 的时间相对应?
【问题讨论】:
标签: perl postgresql dbi