User-Defined Function Statements
1169
The backup for each table consists of its
.frm
format file and
.MYD
data file. The restore operation
restores those files, and then uses them to rebuild the
.MYI
index file. Restoring takes longer than
backing up due to the need to rebuild the indexes. The more indexes the table has, the longer it takes.
RESTORE TABLE
returns a result set with the following columns.
Column
Value
Table
The table name
Op
Always
restore
Msg_type
status
,
error
,
info
,
note
, or
warning
Msg_text
An informational message
13.7.3. User-Defined Function Statements
13.7.3.1.
CREATE FUNCTION
Syntax for User-defined Functions
CREATE [AGGREGATE] FUNCTION
function_name
RETURNS {STRING|INTEGER|REAL|DECIMAL}
SONAME
shared_library_name
A user-defined function (UDF) is a way to extend MySQL with a new function that works like a native
(built-in) MySQL function such as
ABS()
[908]
or
CONCAT()
[887]
.
function_name
is the name that should be used in SQL statements to invoke the function. The
RETURNS
clause indicates the type of the function's return value. As of MySQL 5.0.3,
DECIMAL
is a
legal value after
RETURNS
, but currently
DECIMAL
functions return string values and should be written
like
STRING
functions.
shared_library_name
is the basename of the shared object file that contains the code that
implements the function. As of MySQL 5.0.67, the file must be located in the plugin directory.
This directory is given by the value of the
plugin_dir
[481]
system variable. If the value of
plugin_dir
[481]
is empty, the behavior that is used before 5.0.67 applies: The file must be
located in a directory that is searched by your system's dynamic linker. For more information, see
Section 21.2.2.5, “Compiling and Installing User-Defined Functions”
.
To create a function, you must have the
INSERT
[577]
privilege for the
mysql
database. This is
necessary because
CREATE FUNCTION
adds a row to the
mysql.func
system table that records
the function's name, type, and shared library name. If you do not have this table, you should run the
mysql_upgrade
command to create it. See
Section 4.4.9, “
mysql_upgrade
— Check Tables for
MySQL Upgrade”
.
An active function is one that has been loaded with
CREATE FUNCTION
and not removed with
DROP
FUNCTION
. All active functions are reloaded each time the server starts, unless you start
mysqld
with
the
--skip-grant-tables
[420]
option. In this case, UDF initialization is skipped and UDFs are
unavailable.
For instructions on writing user-defined functions, see
Section 21.2.2, “Adding a New User-Defined
Function”
. For the UDF mechanism to work, functions must be written in C or C++ (or another language
that can use C calling conventions), your operating system must support dynamic loading and you
must have compiled
mysqld
dynamically (not statically).
An
AGGREGATE
function works exactly like a native MySQL aggregate (summary) function such as
SUM
or
COUNT()
[970]
. For
AGGREGATE
to work, your
mysql.func
table must contain a
type
column. If
your
mysql.func
table does not have this column, you should run the
mysql_upgrade
program to
create it (see
Section 4.4.9, “
mysql_upgrade
— Check Tables for MySQL Upgrade”
).
Note
To upgrade the shared library associated with a UDF, issue a
DROP FUNCTION
statement, upgrade the shared library, and then issue a
CREATE FUNCTION
Summary of Contents for 5.0
Page 1: ...MySQL 5 0 Reference Manual ...
Page 18: ...xviii ...
Page 60: ...40 ...
Page 396: ...376 ...
Page 578: ...558 ...
Page 636: ...616 ...
Page 844: ...824 ...
Page 1234: ...1214 ...
Page 1427: ...MySQL Proxy Scripting 1407 ...
Page 1734: ...1714 ...
Page 1752: ...1732 ...
Page 1783: ...Configuring Connector ODBC 1763 ...
Page 1793: ...Connector ODBC Examples 1773 ...
Page 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Page 2850: ...2830 ...
Page 2854: ...2834 ...
Page 2928: ...2908 ...
Page 3000: ...2980 ...
Page 3122: ...3102 ...
Page 3126: ...3106 ...
Page 3174: ...3154 ...
Page 3232: ...3212 ...