I wrote a detailed guide on how to install a SQLite extension, but here is a TLDR (1-2 are about getting the extension, 3-7 are about loading it into SQLite):
- You can find a pre-compiled extension for your operating system (aka "package") in the SQLite package registry.
The standard deviation function is available in the nalgeon/stats
package.
- Alternatively, you can download a
.c
file and compile it using gcc
:
gcc -fPIC -shared extension.c -o extension.so
- For SQLite CLI (
sqlite3.exe
), use the .load
command (I'll use the stats
extension as an example from here on):
.load /Users/anton/Downloads/stats
- For SQLiteStudio, SQLiteSpy, DBeaver and other similar tools, use the
load_extension
function:
select load_extension('/Users/anton/Downloads/stats');
- For Python, use the default
sqlite3
module:
import sqlite3
conn = sqlite3.connect(":memory:")
conn.enable_load_extension(True)
conn.load_extension("/Users/anton/Downloads/stats")
conn.execute("select median(value) from generate_series(1, 99)")
conn.close()
Alternatively, use the sqlean.py
package.
- For Node.js, use the
better-sqlite3
package:
const sqlite3 = require("better-sqlite3");
const db = new sqlite3(":memory:");
db.loadExtension("/Users/anton/Downloads/stats");
db.exec("select median(value) from generate_series(1, 99)");
db.close();
- For Go, use the
mattn/go-sqlite3
package:
package main
import (
"database/sql"
"fmt"
sqlite3 "github.com/mattn/go-sqlite3"
)
func main() {
sql.Register("sqlite3_with_extensions",
&sqlite3.SQLiteDriver{
Extensions: []string{
"/Users/anton/Downloads/stats",
},
})
db, err := sql.Open("sqlite3_with_extensions", ":memory:")
db.Query("select median(value) from generate_series(1, 99)")
db.Close()
}
And that's it!