Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for Built-In Mathematical SQL Functions #77

Closed
rayures opened this issue Nov 29, 2021 · 19 comments
Closed

add support for Built-In Mathematical SQL Functions #77

rayures opened this issue Nov 29, 2021 · 19 comments
Labels
pending-closure This issue is stale and will be cleaned up

Comments

@rayures
Copy link

rayures commented Nov 29, 2021

per v3.35 sqlite has by default enabled Built-In Mathematical SQL Functions.

https://www.sqlite.org/lang_mathfunc.html

installed sqlite v.3.37 on my grafana host, tried a function, but these do not work.
query does work when executing it directly in sqlite.

@fr-ser
Copy link
Owner

fr-ser commented Nov 29, 2021

Can you provide an example query?

@rayures
Copy link
Author

rayures commented Nov 29, 2021

i.e:
SELECT (100*POWER(1.01,365)) as balance FROM BALANCE

the 'power' is from the math functions

@fr-ser
Copy link
Owner

fr-ser commented Dec 14, 2021

The latest release of the SQLite client that is used by the plugin seems to be on SQLite 3.28.0.
Since I need to use the go client it does not look like I can do anything.

Currently latest release: https://github.com/mattn/go-sqlite3/releases/tag/v1.10.0

@fr-ser fr-ser added the pending-closure This issue is stale and will be cleaned up label Dec 14, 2021
@rayures
Copy link
Author

rayures commented Dec 14, 2021

Isnt this the latest version?

https://pkg.go.dev/github.com/mattn/go-sqlite3?tab=versions

1.14.9

(Didn't look at the sqlite version in that version)

@stale stale bot removed the pending-closure This issue is stale and will be cleaned up label Dec 14, 2021
@fr-ser
Copy link
Owner

fr-ser commented Dec 15, 2021

Yeah, you are right. It is just not shown as a Github release. The plugin currently uses this version: v1.14.4

I wouldn't expect significant upgrades to the underlying SQLite version between 1.14.9 and v1.14.4 but if you happen to find which version the latest is running I can try upgrading

@rayures
Copy link
Author

rayures commented Dec 15, 2021

Well, based on the code, it's currently at 3.36.0.

https://github.com/mattn/go-sqlite3/blob/master/sqlite3-binding.h

Line 127.

@fr-ser
Copy link
Owner

fr-ser commented Dec 15, 2021

Neat. I'll test out the new version later and see if the math functions are included 👌🏻

@fr-ser
Copy link
Owner

fr-ser commented Dec 15, 2021

I updated to the newer version of the go library and it still did not recognize the power function.
I tried using the compile time option SQLITE_ENABLE_MATH_FUNCTIONS but I could not find how to pass this for the go client.

I tried using this extension, that was linked in the golang client docs: https://github.com/dinedal/go-sqlite3-extension-functions
But this threw this error: ../../go/pkg/mod/github.com/dinedal/go-sqlite3-extension-functions/go@v0.0.0-20200202173959-679ee1ae1f0b/extension-functions.go:1:18: syntax error: unexpected -, expecting semicolon or newline

To be fair I am not really an expert regarding linking C libraries in go but I am sadly out of idea...

@rayures
Copy link
Author

rayures commented Dec 15, 2021

Hmm, to bad. Sort of hoped/expected it would just work with upgrading the sqlite / go package.

mattn/go-sqlite3#926

@fr-ser
Copy link
Owner

fr-ser commented Dec 16, 2021

Hmm, weird. They even mention the math functions in the version... I will check again later this week. Maybe I did something wrong during the go package upgrade...

@fr-ser
Copy link
Owner

fr-ser commented Dec 17, 2021

I can't get it working... I opened an issue in the underlying library to get see what I am doing wrong...
mattn/go-sqlite3#990

@rayures
Copy link
Author

rayures commented Dec 17, 2021

Tnx for the update and all the time and work in it. I will also follow #990

@fardeadok
Copy link

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!

@stale
Copy link

stale bot commented Jan 24, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the pending-closure This issue is stale and will be cleaned up label Jan 24, 2022
@stale stale bot closed this as completed Feb 8, 2022
@bearbin
Copy link

bearbin commented Jul 12, 2022

There's still a PR pending in go-sqlite3 to add a build tag for maths functions - mattn/go-sqlite3#1037

until then the functions won't work

@fr-ser
Copy link
Owner

fr-ser commented Jul 13, 2022

The plugin is using a different sqlite library by now. The linked issue will not have any impact anymore, sadly.

The current library is https://pkg.go.dev/modernc.org/sqlite

@rayures
Copy link
Author

rayures commented Jul 22, 2022

Latest does have math functions enabled and they are working (at least the power function).

Just noticing that the grafana widget are loading much slower with latest sqlite Datasource plugin

@bearbin
Copy link

bearbin commented Jul 22, 2022

@fr-ser didn't see your message for a while, thanks for correcting me. Good to know that the math functions are now working :)

@fr-ser
Copy link
Owner

fr-ser commented Jul 28, 2022

Latest does have math functions enabled and they are working (at least the power function).

Haha, I didn't even realize that myself. But with the new sqlite package provider it makes sense that some behavior changed 😅

Just noticing that the grafana widget are loading much slower with latest sqlite Datasource plugin

In case the slow down is noticable and consistent could you open a new issue and describe a bit more what you experience?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending-closure This issue is stale and will be cleaned up
Projects
None yet
Development

No branches or pull requests

4 participants