Function Name Parsing and Resolution
756
MySQL 5.0 supports built-in (native) functions, user-defined functions (UDFs), and stored functions.
This section describes how the server recognizes whether the name of a built-in function is used as
a function call or as an identifier, and how the server determines which function to use in cases when
functions of different types exist with a given name.
Built-In Function Name Parsing
The parser uses default rules for parsing names of built-in functions. These rules can be changed by
enabling the
IGNORE_SPACE
[536]
SQL mode.
When the parser encounters a word that is the name of a built-in function, it must determine whether
the name signifies a function call or is instead a nonexpression reference to an identifier such as a
table or column name. For example, in the following statements, the first reference to
count
is a
function call, whereas the second reference is a table name:
SELECT COUNT(*) FROM mytable;
CREATE TABLE count (i INT);
The parser should recognize the name of a built-in function as indicating a function call only when
parsing what is expected to be an expression. That is, in nonexpression context, function names are
permitted as identifiers.
However, some built-in functions have special parsing or implementation considerations, so the parser
uses the following rules by default to distinguish whether their names are being used as function calls
or as identifiers in nonexpression context:
• To use the name as a function call in an expression, there must be no whitespace between the name
and the following “
(
” parenthesis character.
• Conversely, to use the function name as an identifier, it must not be followed immediately by a
parenthesis.
The requirement that function calls be written with no whitespace between the name and the
parenthesis applies only to the built-in functions that have special considerations.
COUNT
is one such
name. The exact list of function names for which following whitespace determines their interpretation
are those listed in the
sql_functions[]
array of the
sql/lex.h
source file. Before MySQL
5.1, they are rather numerous (about 200), so you may find it easiest to treat the no-whitespace
requirement as applying to all function calls. In MySQL 5.1, parser improvements reduce to about 30
the number of affected function names.
For functions not listed in the
sql_functions[]
) array, whitespace does not matter. They are
interpreted as function calls only when used in expression context and may be used freely as identifiers
otherwise.
ASCII
is one such name. However, for these nonaffected function names, interpretation
may vary in expression context:
func_name ()
is interpreted as a built-in function if there is one with
the given name; if not,
func_name ()
is interpreted as a user-defined function or stored function if
one exists with that name.
The
IGNORE_SPACE
[536]
SQL mode can be used to modify how the parser treats function names that
are whitespace-sensitive:
• With
IGNORE_SPACE
[536]
disabled, the parser interprets the name as a function call when there is
no whitespace between the name and the following parenthesis. This occurs even when the function
name is used in nonexpression context:
mysql>
CREATE TABLE count(i INT);
ERROR 1064 (42000): You have an error in your SQL syntax ...
near 'count(i INT)'
To eliminate the error and cause the name to be treated as an identifier, either use whitespace
following the name or write it as a quoted identifier (or both):
CREATE TABLE count (i INT);
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 ...