- my $pkg = $dbh->selectrow_hashref('SELECT *, extract(days from date_trunc(\'days\', now() - state_change)) as state_days FROM ' .
- table_name() . ' WHERE package = ? AND distribution = ?',
+ my $q = 'SELECT rel, priority, state_change, permbuildpri, section, buildpri, failed, state, binary_nmu_changelog, bd_problem, version, package, distribution, installed_version, notes, failed_category, builder, old_failed, previous_state, binary_nmu_version, depends, extract(days from date_trunc(\'days\', now() - state_change)) as state_days, successtime.build_time as successtime, anytime.build_time as anytime FROM ' .
+ table_name() .
+ ' left join ( '.
+ 'select distinct on (package, distribution) build_time, package, distribution from '.pkg_history_table_name().' where result = \'successful\' order by package, distribution, timestamp desc '.
+ ' ) as successtime using (package, distribution) '.
+ ' left join ( '.
+ 'select distinct on (package, distribution) build_time, package, distribution from '.pkg_history_table_name().' order by package, distribution, timestamp desc'.
+ ' ) as anytime using (package, distribution) '.
+ ' WHERE package = ? AND distribution = ?';
+ my $pkg = $dbh->selectrow_hashref( $q,