CREATE FUNCTION

  1. CREATE FUNCTION udf_name
  2. RETURNS {INT | INTEGER | BIGINT | FLOAT | STRING}
  3. SONAME 'udf_lib_file'

CREATE FUNCTION statement installs a user-defined function UDF with the given name and type from the given library file. The library file must reside in a trusted plugin_dir directory. On success, the function is available for use in all subsequent queries that the server receives. Example:

  1. mysql> CREATE FUNCTION avgmva RETURNS INTEGER SONAME 'udfexample.dll';
  2. Query OK, 0 rows affected (0.03 sec)
  3. mysql> SELECT *, AVGMVA(tag) AS q from test1;
  4. +------+--------+---------+-----------+
  5. | id | weight | tag | q |
  6. +------+--------+---------+-----------+
  7. | 1 | 1 | 1,3,5,7 | 4.000000 |
  8. | 2 | 1 | 2,4,6 | 4.000000 |
  9. | 3 | 1 | 15 | 15.000000 |
  10. | 4 | 1 | 7,40 | 23.500000 |
  11. +------+--------+---------+-----------+

DROP FUNCTION

  1. DROP FUNCTION udf_name

DROP FUNCTION statement deinstalls a `user-defined function UDF with the given name. On success, the function is no longer available for use in subsequent queries. Pending concurrent queries will not be affected and the library unload, if necessary, will be postponed until those queries complete. Example:

  1. mysql> DROP FUNCTION avgmva;
  2. Query OK, 0 rows affected (0.00 sec)

Plugins