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

Is it worth compiling in math functions by default?

Open c9845 opened this issue 9 months ago • 3 comments

To use math functions like pow() and round(), you currently have to do go build -tags "sqlite_math_functions" .... This works, but this build tag is often forgotten/missed until an error like "not such function" is kicked out.

I think it should be considered to add the math functions into builds by default (aka no build tag required). I think it is common enough to use round(), 'floor(), and ceil() that adding the math functions by default would make sense.

This would help adapting SQL queries from MySQL/MariaDB or Postgres where the math functionality is always present. It would also help swapping in this library versus the modernc/cznic library that has the math functionality enabled by default [1]

[1] https://gitlab.com/cznic/sqlite/-/tags/v1.14.5

c9845 avatar May 06 '24 18:05 c9845

So, looking into this, I am pretty sure this is as simple as removing the below lines from the sqlite3_opt_math_functions.go file.

//go:build sqlite_math_functions
// +build sqlite_math_functions

c9845 avatar May 15 '24 18:05 c9845

Obviously, the README would need updated to either remove the "Math Functions" from the "Feature/Extension List" table too (or note that the math functions are built-in).

c9845 avatar May 15 '24 18:05 c9845

This does not affect round(), but does affect floor() and ceil() as well as everything else from this page [1]

[1] https://www.sqlite.org/lang_mathfunc.html

c9845 avatar Jul 09 '24 15:07 c9845