If you are going to implement UDFs, please see these reference pages:
Adding a New User-Defined Function
Writing MySQL UDFs
mysqludf.org
08-06-2018:
Makefile changed to produce libudf_astro.so instead of udf_astro.so. Download it and recompile.
To install our demo functions:
shell> cd Soft/C/UDFs make sudo make install
Then in MySQL:
mysql> CREATE FUNCTION skysepc RETURNS REAL SONAME 'libudf_astro.so'; CREATE FUNCTION radec2gl RETURNS REAL SONAME 'libudf_astro.so'; CREATE FUNCTION radec2gb RETURNS REAL SONAME 'libudf_astro.so'; CREATE FUNCTION radec2el RETURNS REAL SONAME 'libudf_astro.so'; CREATE FUNCTION radec2eb RETURNS REAL SONAME 'libudf_astro.so'; SELECT * FROM mysql.func; +-------------------+-----+-----------------+----------+ | name | ret | dl | type | +-------------------+-----+-----------------+----------+ ... | skysepc | 1 | libudf_astro.so | function | ...
The last command lists the currently defined functions. The ret integer field can be 0, 1, 2.
They refer to the type of returned value which can be, in C/C++ notation, char*, double, long long,
corresponding to the three main SQL Types STRING, REAL, INTEGER, respectively.
On MySQL 8 you can list all the UDFs:
mysql> SELECT * FROM performance_schema.user_defined_functions; +--------------------------+-----------------+----------+------------------+-----------------+ | UDF_NAME | UDF_RETURN_TYPE | UDF_TYPE | UDF_LIBRARY | UDF_USAGE_COUNT | +--------------------------+-----------------+----------+------------------+-----------------+ | radec2gl | double | function | libudf_astro.so | 1 | | radec2el | double | function | libudf_astro.so | 1 | | radec2eb | double | function | libudf_astro.so | 1 | ...
Examples of usage:
mysql> select radec2gl(ramas/3.6e6, decmas/3.6e6) as Gl, radec2gb(ramas/3.6e6, decmas/3.6e6) as Gb from ascc25_initial limit 3; select radec2el(ramas/3.6e6, decmas/3.6e6) as El, radec2eb(ramas/3.6e6, decmas/3.6e6) as Eb from ascc25_initial limit 3; select skysepc(2, 4, ramas/3.6e6, decmas/3.6e6)/60 as d_deg from ascc25_initial limit 3;