0

I am looking to add aggregate functions based on Robert Harvey's response here where he points to this page. I see the first file [extension-functions.c ], which is what I need (the variance function in particular).

How do I add this file's functionality to my sqlite3 console? Will it matter if I am working on a Mac?

I have tried searching for answer presuming the file is called an extension but the word extension also means what goes at the end of the file (.db, .db3 or .sqlite3) so Google hasn't been useful.

heretoinfinity
  • 1,528
  • 3
  • 14
  • 33
  • 2
    The file in question is a source code file. You have to build it as a shared library and use the `load_extension()` SQL function to load that library so SQLite can use the functions it contains. – Mark Benningfield Feb 05 '18 at 16:38

1 Answers1

1

In addition to @Mark Benningfield's comment:

I found the a link to the file the github of the file on this post (I don't use Ubuntu that's why I missed it) where the accepted answer wasn't what I was looking for. However, the Github link provided documentation, which was what I was in search of.

On a Mac, I had to run the following in my console:

-compile the file

gcc -fno-common -dynamiclib extension-functions.c -o libsqlitefunctions.dylib

-load sqlite console

sqlite3 <database_name>

-run in the SQLite console

SELECT load_extension('./libsqlitefunctions.dylib');

Note that the above line has to be run every time you need to use external functions (like those in the extension-functions.c, the file in question). For a permanent load at startup and for other operating systems see the same post. I haven't tried done the latter yet so I can't vouch for anything else apart from a macOS.

heretoinfinity
  • 1,528
  • 3
  • 14
  • 33