array
Package array provides the array table-valued SQL function — a way to feed a Go slice into a SQL query as a single-column table.
The vtab is a Go-native re-implementation of SQLite’s bundled carray (https://sqlite.org/carray.html) and the equivalent ncruces/ext/array module.
Transparent binding (preferred)
Section titled “Transparent binding (preferred)”Wrap the slice with sqlite.Pointer and pass it as a regular query argument. SQLite’s destructor callback releases the binding when the statement finalizes — no caller-side cleanup needed.
import ( sqlite "gosqlite.org" "gosqlite.org/ext/array")
if err := array.Register(conn); err != nil { ... }
rows, _ := db.QueryContext(ctx, `SELECT value FROM array(?) ORDER BY value`, sqlite.Pointer([]int{10, 20, 30}))Explicit Bind / Release (escape hatch)
Section titled “Explicit Bind / Release (escape hatch)”For long-lived bindings (same slice across many queries) or when an int64 sentinel is more convenient than a wrapped argument, the explicit pair stays available:
token, release := array.Bind(conn, []int{10, 20, 30})defer release()rows, _ := db.QueryContext(ctx, `SELECT value FROM array(?) ORDER BY value`, token)Supported element types
Section titled “Supported element types”Bind accepts any of:
- []int, []int8, []int16, []int32, []int64
- []uint8 (treated as a single BLOB), []uint16, []uint32, []uint64
- []float32, []float64
- []bool
- []string
- [][]byte
- []any (each element coerced as above; nil becomes SQL NULL)
Anything else is reflect-walked; element kinds not in the list above surface a clear MISMATCH error from the cursor.
Blank-import auto-registration
Section titled “Blank-import auto-registration”For a pool-wide install via gosqlite.org.Driver.ConnectHook, blank-import the auto sub-package:
import _ "gosqlite.org/ext/array/auto"Full API: pkg.go.dev/gosqlite.org/ext/array