mirror of
https://github.com/grafana/grafana.git
synced 2026-08-26 21:37:31 -05:00
Search: sort results correctly when using postgres (#46466)
* Search: sort results correctly when using postgres postgresql puts nulls first while both mysql and sqlite puts them last * linting
This commit is contained in:
@@ -284,6 +284,19 @@ func (db *PostgresDialect) Lock(cfg LockCfg) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// OrderBy normalizes ordering so that nulls end up last in sorting, which they do by default in both sqlite and mysql but not postgres
|
||||
// order should be a string like `dashboard.id ASC`
|
||||
func (db *PostgresDialect) OrderBy(order string) string {
|
||||
nullSort := "FIRST"
|
||||
normalizedOrder := strings.ToUpper(strings.TrimSpace(order))
|
||||
|
||||
if strings.HasSuffix(normalizedOrder, " DESC") {
|
||||
nullSort = "LAST"
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%s NULLS %s", order, nullSort)
|
||||
}
|
||||
|
||||
func (db *PostgresDialect) Unlock(cfg LockCfg) error {
|
||||
// trying to release a previously-acquired exclusive session level advisory lock.
|
||||
// it will either return true if the lock is successfully released or
|
||||
|
||||
Reference in New Issue
Block a user