Documentation
¶
Overview ¶
Package stats gives SQLite the variance and the standard deviation as aggregate functions:
sqlite.NewConnector(dsn, stats.Option())
Then var_samp(x), var_pop(x), stddev_samp(x) and stddev_pop(x), with stddev and variance as other names of the sample ones, as in PostgreSQL. NULLs are skipped. The sample ones give NULL for fewer than 2 values, the population ones for none. A text or a blob is an error, and so are values whose variance does not fit a float64.
Example ¶
package main
import (
"database/sql"
"fmt"
"github.com/liustack/sqlite"
"github.com/liustack/sqlite/ext/stats"
)
func main() {
c, err := sqlite.NewConnector(":memory:", stats.Option())
if err != nil {
panic(err)
}
db := sql.OpenDB(c)
defer db.Close()
var samp, pop float64
err = db.QueryRow(`SELECT stddev(column1), stddev_pop(column1) FROM (VALUES (2), (4), (4), (4), (5), (5), (7), (9))`).Scan(&samp, &pop)
if err != nil {
panic(err)
}
fmt.Printf("%.4f %.4f\n", samp, pop)
}
Output: 2.1381 2.0000
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.