stats

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 4 Imported by: 0

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

func Option

func Option() sqlite.Option

Option adds the functions to a connector.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL