Files
grafana/pkg/storage/unified/sql/sqltemplate/dialect_postgresql.go
Peter Štibraný e076c74869 sqltemplate, dbimpl: Remove single-method function types (#107525)
* Remove dbProviderFunc function.

This removes one extra indirection that made the code bit more difficult to navigate.

* Remove indirection function types implementing single-method interfaces.

This streamlines the code and makes it bit easier to navigate.

* Update pkg/storage/unified/sql/sqltemplate/dialect_mysql.go

Co-authored-by: Mustafa Sencer Özcan <32759850+mustafasencer@users.noreply.github.com>

---------

Co-authored-by: Mustafa Sencer Özcan <32759850+mustafasencer@users.noreply.github.com>
2025-07-03 10:38:12 +02:00

43 lines
940 B
Go

package sqltemplate
import (
"errors"
"fmt"
"strings"
)
// PostgreSQL is an implementation of Dialect for the PostgreSQL DMBS.
var PostgreSQL = postgresql{}
var (
ErrPostgreSQLUnsupportedIdent = errors.New("identifiers in PostgreSQL cannot contain the character with code zero")
)
type postgresql struct{}
func (p postgresql) DialectName() string {
return "postgres"
}
func (p postgresql) ArgPlaceholder(argNum int) string {
return fmt.Sprintf("$%d", argNum)
}
func (p postgresql) SelectFor(s ...string) (string, error) {
return rowLockingClauseAll.SelectFor(s...)
}
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 standardIdent(s)
}
func (postgresql) CurrentEpoch() string {
return "(EXTRACT(EPOCH FROM statement_timestamp()) * 1000000)::BIGINT"
}