Skip to content

Use of custom SQLite functions. #217

Closed Answered by ncruces
dm-turing asked this question in Q&A
Discussion options

You must be logged in to vote

SQLite does not support stored procedures (CREATE FUNCTION) so I'm not sure what you mean when you say mattn supports it.

You can create custom functions in Go (not in PL/SQL).

There are a bunch of examples in the repo, like this one:

go-sqlite3/func_test.go

Lines 80 to 82 in e2da469

err = db.CreateFunction("upper", 1, sqlite3.DETERMINISTIC|sqlite3.INNOCUOUS, func(ctx sqlite3.Context, arg ...sqlite3.Value) {
ctx.ResultRawText(bytes.ToUpper(arg[0].RawText()))
})

This function receives a single TEXT argument, uppercases it with bytes.ToUpper, and returns it.

SQLite documentation for this is here: https://sqlite.org/appfunc.html

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by dm-turing
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants