postgres: fix precision for time columns in time series query mode

This commit is contained in:
Marcus Efraimsson
2018-04-10 11:03:58 +02:00
parent af62646624
commit 1783c534fd
2 changed files with 229 additions and 27 deletions

View File

@ -7,7 +7,6 @@ import (
"math"
"net/url"
"strconv"
"time"
"github.com/go-xorm/core"
"github.com/grafana/grafana/pkg/components/null"
@ -219,13 +218,16 @@ func (e PostgresQueryEndpoint) transformToTimeSeries(query *tsdb.Query, rows *co
return err
}
// converts column named time to unix timestamp in milliseconds to make
// native mysql datetime types and epoch dates work in
// annotation and table queries.
tsdb.ConvertSqlTimeColumnToEpochMs(values, timeIndex)
switch columnValue := values[timeIndex].(type) {
case int64:
timestamp = float64(columnValue * 1000)
timestamp = float64(columnValue)
case float64:
timestamp = columnValue * 1000
case time.Time:
timestamp = float64(columnValue.UnixNano() / 1e6)
timestamp = columnValue
default:
return fmt.Errorf("Invalid type for column time, must be of type timestamp or unix timestamp, got: %T %v", columnValue, columnValue)
}