mirror of
https://github.com/grafana/grafana.git
synced 2025-08-02 13:45:29 +08:00

* Use epoch with microsecond resolution as RV * fix backend tests * Add solution for when the clock goes back * Add solution for when the clock goes back * generate mocks * go lint * remove comment * Use Greatest instead of max in msyql and postgres * update tests * Update pkg/storage/unified/sql/sqltemplate/dialect_sqlite.go Co-authored-by: Diego Augusto Molina <diegoaugustomolina@gmail.com> * cast to bigint * add additional round trip * increment the RV using 2 sql round trips instead of 3 * cleanup comments * cast unix timestamp to integer * fix postgres query * remove old increment test data * remove greatest * cast unix_timestamp to signed * Use statement_timestamp instead of clock_timestamp --------- Co-authored-by: Diego Augusto Molina <diegoaugustomolina@gmail.com>
42 lines
915 B
Go
42 lines
915 B
Go
package sqltemplate
|
|
|
|
import (
|
|
"errors"
|
|
"strings"
|
|
)
|
|
|
|
// PostgreSQL is an implementation of Dialect for the PostgreSQL DMBS.
|
|
var PostgreSQL = postgresql{
|
|
rowLockingClauseMap: rowLockingClauseAll,
|
|
argPlaceholderFunc: argFmtPositional,
|
|
name: "postgres",
|
|
}
|
|
|
|
var _ Dialect = PostgreSQL
|
|
|
|
// PostgreSQL-specific errors.
|
|
var (
|
|
ErrPostgreSQLUnsupportedIdent = errors.New("identifiers in PostgreSQL cannot contain the character with code zero")
|
|
)
|
|
|
|
type postgresql struct {
|
|
standardIdent
|
|
rowLockingClauseMap
|
|
argPlaceholderFunc
|
|
name
|
|
}
|
|
|
|
func (p postgresql) Ident(s string) (string, error) {
|
|
// See:
|
|
// https://www.postgresql.org/docs/current/sql-syntax-lexical.html
|
|
if strings.IndexByte(s, 0) != -1 {
|
|
return "", ErrPostgreSQLUnsupportedIdent
|
|
}
|
|
|
|
return p.standardIdent.Ident(s)
|
|
}
|
|
|
|
func (postgresql) CurrentEpoch() string {
|
|
return "(EXTRACT(EPOCH FROM statement_timestamp()) * 1000000)::BIGINT"
|
|
}
|