MySQL: User Defined Function example

04-11-2018
Download mysql source: ```bash wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.15.tar.gz tar -xvf mysql-5.6.15.tar.gz ``` This repo contains many useful udf's including median. Download the function: ```bash wget https://github.com/megastep/mysql-udf/blob/master/udf_median.cc ``` Compile it: (tested with ubuntu) ```bash gcc -Wall -fPIC -I . mysql-5.6.15/include -c udf_median.cc -o udf_median.o ld -shared -o udf_median.so udf_median.o Copy it to the plugins dir: sudo cp udf_median.so /usr/lib/mysql/plugin/ ``` Open mysql and load the function: ```sql CREATE AGGREGATE FUNCTION median RETURNS REAL SONAME 'udf_median.so'; ``` To drop it: ```sql DROP FUNCTION median; ```
MySQL

Amura