go-sqlite3 icon indicating copy to clipboard operation
go-sqlite3 copied to clipboard

Trying to use maths function (from SQLite v3.35) does not work

Open fr-ser opened this issue 3 years ago • 4 comments

Since this PR the underlying version of SQLite should be >=3.35 (and it is). The PR even mentions the new maths function added. However, when I try to use math functions (like SELECT power(2,2)) I get this error no such function: power.

Is there something more I need to do than use the latest version of the go-sqlite3 library?

fr-ser avatar Dec 17 '21 07:12 fr-ser

As per the SQLite docs, in order to leverage the built-in math functions, you must compile with -DSQLITE_ENABLE_MATH_FUNCTIONS https://www.sqlite.org/lang_mathfunc.html

However, currently there is no way to include that option with this library. Please add a build tag for it, as was done for -DSQLITE_DEFAULT_FOREIGN_KEYS. https://github.com/mattn/go-sqlite3/blob/master/sqlite3_opt_foreign_keys.go

You'll also want to add an entry to the table in the README. https://github.com/mattn/go-sqlite3#feature--extension-list

rittneje avatar Dec 17 '21 14:12 rittneje

I didn't understand: is it possible to use pow and sqrt or not? If not, when will it be fixed? I spent a couple of days trying to figure out why sqllite works differently in different applications!

fardeadok avatar Dec 26 '21 09:12 fardeadok

is it possible to use pow and sqrt or not?

It is not currently possible to use the built-in math functions, because to do so requires the -DSQLITE_ENABLE_MATH_FUNCTIONS flag to be passed to the C library at compile-time.

If not, when will it be fixed?

You need to raise a PR with the aforementioned changes.

rittneje avatar Dec 26 '21 14:12 rittneje

Hi, I came across this issue when trying to use SQRT function in an application. I added the changes @rittneje mentioned and create a PR, I hope it is correctly implemented. At least on my local test system I can successfully use the scalar math functions afterwards

nkt-dk avatar Apr 29 '22 19:04 nkt-dk