series

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: MIT Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package series gives SQLite generate_series, the table-valued function of SQLite's series extension (ext/misc/series.c), ported to Go:

sqlite.NewConnector(dsn, series.Option())

Then:

SELECT value FROM generate_series(start, stop, step)

gives start, start+step, ... up to stop. stop defaults to 4294967295 and step to 1, a step of 0 is 1, and a negative step counts down from start to stop. start may be left out when a WHERE clause bounds value instead: generate_series WHERE value BETWEEN 1 AND 10. A NULL argument gives no rows. The hidden columns start, stop and step give the arguments.

The arguments are 64-bit integers. A REAL is cut to an integer as SQLite's own does. A TEXT or BLOB argument, or one compared with value in the WHERE clause (value = '5', or a Go string bound to value = ?), is an error where SQLite's would read the number at its start: write CAST(x AS INTEGER).

Where SQLite's own gives wrong rows or fails, this one gives the right rows: a LIMIT with an ORDER BY the sequence does not follow on its own (ORDER BY rowid DESC LIMIT 3), a REAL compared with value at the ends of the 64-bit range, a join that gives the start through value (JOIN generate_series s ON s.value = t.x), and a LIMIT on a sequence that counts down.

Example
package main

import (
	"database/sql"
	"fmt"

	"github.com/liustack/sqlite"
	"github.com/liustack/sqlite/ext/series"
)

func main() {
	c, err := sqlite.NewConnector(":memory:", series.Option())
	if err != nil {
		panic(err)
	}
	db := sql.OpenDB(c)
	defer db.Close()
	rows, err := db.Query(`SELECT value FROM generate_series(0, 20, 5)`)
	if err != nil {
		panic(err)
	}
	defer rows.Close()
	for rows.Next() {
		var v int
		if err := rows.Scan(&v); err != nil {
			panic(err)
		}
		fmt.Print(v, " ")
	}
	if err := rows.Err(); err != nil {
		panic(err)
	}
	fmt.Println()
}
Output:
0 5 10 15 20

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Option

func Option() sqlite.Option

Option adds generate_series 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