Directly, no, there's not. But you can do an indirect and pretty close estimate by checking the time right before and right after the query you're interested in timing.
$sql = "Your Query";
$bm = "SELECT extract(epoch FROM clock_timestamp())";
$query = "{$bm}; {$sql}; {$bm};";
Function clock_timestamp() gives you the server actual time when the statement starts. Since that SELECT involves no tables, we can expect it to be almost instantaneous. I guess any Pg driver offers support for multiple queries; it is important that these 3 queries (the real one and the 2 extras) go together, else you'd be measuring data transport times as well...
For PHP I have a function to handle this. In summary it goes like:
<?php
function pgquery($sql, $conn)
{
// Prepend and append benchmarking queries
$bm = "SELECT extract(epoch FROM clock_timestamp())";
$query = "{$bm}; {$sql}; {$bm};";
// Execute the query, and time it (data transport included)
$ini = microtime(true);
pg_send_query($conn, $query);
while ($resource = pg_get_result($conn))
{
$resources[] = $resource;
}
$end = microtime(true);
// "Extract" the benchmarking results
$q_ini = pg_fetch_row(array_shift($resources));
$q_end = pg_fetch_row(array_pop($resources));
// Compute times
$time = round($end - $ini, 4); # Total time (inc. transport)
$q_time = round($q_end[0] - $q_ini[0], 4); # Query time (Pg server only)
return $resources;
}
?>
I just left the basics there. $conn holds a link to a Pg connection, and $resources is an array of returned pg resources (in case you sent multiple queries in your $sql).
$time holds total time since the query left for the Pg server until the result arrives. $q-time only holds the actual query time you wanted (or a very good approximation).
Add error handling and other processing to your liking, I have plenty but it's irrelevant to your question.