NuSphere editor's changes to pages 151-200 of manual.texi.

parent f96ee774
...@@ -11557,7 +11557,7 @@ have the necessary privileges to perform the request, but the server cannot ...@@ -11557,7 +11557,7 @@ have the necessary privileges to perform the request, but the server cannot
tell that from either table by itself; the privileges granted by the entries tell that from either table by itself; the privileges granted by the entries
in both tables must be combined. in both tables must be combined.
The @code{host} table can be used to maintain a list of ``secure'' servers. The @code{host} table can be used to maintain a list of secure servers.
At TcX, the @code{host} table contains a list of all machines on the local At TcX, the @code{host} table contains a list of all machines on the local
network. These are granted all privileges. network. These are granted all privileges.
...@@ -11577,12 +11577,12 @@ like this: ...@@ -11577,12 +11577,12 @@ like this:
+--------------------+----+- +--------------------+----+-
@end example @end example
Naturally, you should always test your entries in the grant tables (e.g., Naturally, you should always test your entries in the grant tables (for
using @code{mysqlaccess}) to make sure your access privileges are actually example, using @code{mysqlaccess}) to make sure your access privileges are
set up the way you think they are. actually set up the way you think they are.
@node Privilege changes, Default privileges, Request access, Privilege system @node Privilege changes, Default privileges, Request access, Privilege system
@section When privilege changes take effect @section When Privilege Changes Take Effect
When @code{mysqld} starts, all grant table contents are read into memory and When @code{mysqld} starts, all grant table contents are read into memory and
become effective at that point. become effective at that point.
...@@ -11615,7 +11615,7 @@ Global privilege changes and password changes take effect the next time the ...@@ -11615,7 +11615,7 @@ Global privilege changes and password changes take effect the next time the
client connects. client connects.
@node Default privileges, Adding users, Privilege changes, Privilege system @node Default privileges, Adding users, Privilege changes, Privilege system
@section Setting up the initial MySQL privileges @section Setting Up the Initial MySQL Privileges
After installing @strong{MySQL}, you set up the initial access privileges by After installing @strong{MySQL}, you set up the initial access privileges by
running @code{scripts/mysql_install_db}. running @code{scripts/mysql_install_db}.
...@@ -11629,7 +11629,7 @@ of privileges: ...@@ -11629,7 +11629,7 @@ of privileges:
The @strong{MySQL} @code{root} user is created as a superuser who can do The @strong{MySQL} @code{root} user is created as a superuser who can do
anything. Connections must be made from the local host. anything. Connections must be made from the local host.
@strong{Note:} @strong{NOTE:}
The initial @code{root} password is empty, so anyone can connect as @code{root} The initial @code{root} password is empty, so anyone can connect as @code{root}
@emph{without a password} and be granted all privileges. @emph{without a password} and be granted all privileges.
...@@ -11660,7 +11660,8 @@ mysql> UPDATE user SET Password=PASSWORD('new_password') ...@@ -11660,7 +11660,8 @@ mysql> UPDATE user SET Password=PASSWORD('new_password')
mysql> FLUSH PRIVILEGES; mysql> FLUSH PRIVILEGES;
@end example @end example
You can in @strong{MySQL} 3.22 and above use the @code{SET PASSWORD} statement: You can, in @strong{MySQL} Version 3.22 and above, use the @code{SET PASSWORD}
statement:
@example @example
shell> mysql -u root mysql shell> mysql -u root mysql
...@@ -11673,13 +11674,13 @@ Another way to set the password is by using the @code{mysqladmin} command: ...@@ -11673,13 +11674,13 @@ Another way to set the password is by using the @code{mysqladmin} command:
shell> mysqladmin -u root password new_password shell> mysqladmin -u root password new_password
@end example @end example
Only user with write/update access to the mysql database can change the Only users with write/update access to the mysql database can change the
password for others user. All normal users (not anonymous ones) can only password for others users. All normal users (not anonymous ones) can only
change his own password with either of the above commands or with change their own password with either of the above commands or with
@code{SET PASSWORD=PASSWORD('new password')} @code{SET PASSWORD=PASSWORD('new password')}.
Note that if you update the password in the @code{user} table directly using Note that if you update the password in the @code{user} table directly using
the first method, you must tell the server to reread the grant tables (with the first method, you must tell the server to re-read the grant tables (with
@code{FLUSH PRIVILEGES}), because the change will go unnoticed otherwise. @code{FLUSH PRIVILEGES}), because the change will go unnoticed otherwise.
Once the @code{root} password has been set, thereafter you must supply that Once the @code{root} password has been set, thereafter you must supply that
...@@ -11696,20 +11697,20 @@ add other users. ...@@ -11696,20 +11697,20 @@ add other users.
If you want the initial privileges to be different than those just described If you want the initial privileges to be different than those just described
above, you can modify @code{mysql_install_db} before you run it. above, you can modify @code{mysql_install_db} before you run it.
To recreate the grant tables completely, remove all the @file{*.frm}, To re-create the grant tables completely, remove all the @file{.frm},
@file{*.MYI} and @file{*.MYD} files in the directory containing the @file{.MYI}, and @file{.MYD} files in the directory containing the
@code{mysql} database. (This is the directory named @file{mysql} under @code{mysql} database. (This is the directory named @file{mysql} under
the database directory, which is listed when you run @code{mysqld the database directory, which is listed when you run @code{mysqld
--help}.) Then run the @code{mysql_install_db} script, possibly after --help}.) Then run the @code{mysql_install_db} script, possibly after
editing it first to have the privileges you want. editing it first to have the privileges you want.
@strong{NOTE:} For @strong{MySQL} versions older than 3.22.10, you should NOT @strong{NOTE:} For @strong{MySQL} versions older than Version 3.22.10,
delete the @file{*.frm} files. If you accidentally do this, you should you should NOT delete the @file{.frm} files. If you accidentally do this,
copy them back from your @strong{MySQL} distribution before running you should copy them back from your @strong{MySQL} distribution before
@code{mysql_install_db}. running @code{mysql_install_db}.
@node Adding users, Passwords, Default privileges, Privilege system @node Adding users, Passwords, Default privileges, Privilege system
@section Adding new user privileges to MySQL @section Adding New User Privileges to MySQL
You can add users two different ways: by using @code{GRANT} statements You can add users two different ways: by using @code{GRANT} statements
or by manipulating the @strong{MySQL} grant tables directly. The or by manipulating the @strong{MySQL} grant tables directly. The
...@@ -11748,14 +11749,14 @@ use a password @code{'some_pass'} to do so. Note that we must issue ...@@ -11748,14 +11749,14 @@ use a password @code{'some_pass'} to do so. Note that we must issue
@code{monty@@"%"}. If we don't add the entry with @code{localhost}, the @code{monty@@"%"}. If we don't add the entry with @code{localhost}, the
anonymous user entry for @code{localhost} that is created by anonymous user entry for @code{localhost} that is created by
@code{mysql_install_db} will take precedence when we connect from the local @code{mysql_install_db} will take precedence when we connect from the local
host, because it has a more specific @code{Host} field value and thuse comes host, because it has a more specific @code{Host} field value and thus comes
earlier in the @code{user} table sort order. earlier in the @code{user} table sort order.
@item admin @item admin
A user who can connect from @code{localhost} without a password and who is A user who can connect from @code{localhost} without a password and who is
granted the @strong{reload} and @strong{process} administrative privileges. granted the @strong{reload} and @strong{process} administrative privileges.
This allows the user to execute the @code{mysqladmin reload}, This allows the user to execute the @code{mysqladmin reload},
@code{mysqladmin refresh} and @code{mysqladmin flush-*} commands, as well as @code{mysqladmin refresh}, and @code{mysqladmin flush-*} commands, as well as
@code{mysqladmin processlist} . No database-related privileges are granted. @code{mysqladmin processlist} . No database-related privileges are granted.
(They can be granted later by issuing additional @code{GRANT} statements.) (They can be granted later by issuing additional @code{GRANT} statements.)
...@@ -11784,9 +11785,9 @@ mysql> FLUSH PRIVILEGES; ...@@ -11784,9 +11785,9 @@ mysql> FLUSH PRIVILEGES;
@end example @end example
Depending on your @strong{MySQL} version, you may have to use a different Depending on your @strong{MySQL} version, you may have to use a different
number of @code{'Y'} values above (versions prior to 3.22.11 had fewer number of @code{'Y'} values above (versions prior to Version 3.22.11 had fewer
privilege columns). For the @code{admin} user, the more readable extended privilege columns). For the @code{admin} user, the more readable extended
@code{INSERT} syntax that is available starting with 3.22.11 is used. @code{INSERT} syntax that is available starting with Version 3.22.11 is used.
Note that to set up a superuser, you need only create a @code{user} table Note that to set up a superuser, you need only create a @code{user} table
entry with the privilege fields set to @code{'Y'}. No @code{db} or entry with the privilege fields set to @code{'Y'}. No @code{db} or
...@@ -11798,9 +11799,9 @@ are assigned the default value of @code{'N'}. This is the same thing that ...@@ -11798,9 +11799,9 @@ are assigned the default value of @code{'N'}. This is the same thing that
@code{GRANT USAGE} does. @code{GRANT USAGE} does.
The following example adds a user @code{custom} who can connect from hosts The following example adds a user @code{custom} who can connect from hosts
@code{localhost}, @code{server.domain} and @code{whitehouse.gov}. He wants @code{localhost}, @code{server.domain}, and @code{whitehouse.gov}. He wants
to access the @code{bankaccount} database only from @code{localhost}, to access the @code{bankaccount} database only from @code{localhost},
the @code{expenses} database only from @code{whitehouse.gov} and the @code{expenses} database only from @code{whitehouse.gov}, and
the @code{customer} database from all three hosts. He wants the @code{customer} database from all three hosts. He wants
to use the password @code{stupid} from all three hosts. to use the password @code{stupid} from all three hosts.
...@@ -11856,7 +11857,7 @@ allow user @code{custom} to connect from the various hosts with the given ...@@ -11856,7 +11857,7 @@ allow user @code{custom} to connect from the various hosts with the given
password, but grant no permissions to him (all privileges are set to the password, but grant no permissions to him (all privileges are set to the
default value of @code{'N'}). The next three @code{INSERT} statements add default value of @code{'N'}). The next three @code{INSERT} statements add
@code{db} table entries that grant privileges to @code{custom} for the @code{db} table entries that grant privileges to @code{custom} for the
@code{bankaccount}, @code{expenses} and @code{customer} databases, but only @code{bankaccount}, @code{expenses}, and @code{customer} databases, but only
when accessed from the proper hosts. As usual, when the grant tables are when accessed from the proper hosts. As usual, when the grant tables are
modified directly, the server must be told to reload them (with modified directly, the server must be told to reload them (with
@code{FLUSH PRIVILEGES}) so that the privilege changes take effect. @code{FLUSH PRIVILEGES}) so that the privilege changes take effect.
...@@ -11879,14 +11880,14 @@ mysql> INSERT INTO user VALUES ('%.mydomainname.com', 'myusername', ...@@ -11879,14 +11880,14 @@ mysql> INSERT INTO user VALUES ('%.mydomainname.com', 'myusername',
mysql> FLUSH PRIVILEGES; mysql> FLUSH PRIVILEGES;
@end example @end example
You can also use @code{xmysqladmin}, @code{mysql_webadmin} and even You can also use @code{xmysqladmin}, @code{mysql_webadmin}, and even
@code{xmysql} to insert, change and update values in the grant tables. @code{xmysql} to insert, change and update values in the grant tables.
You can find these utilities in the You can find these utilities in the
@uref{http://www.mysql.com/Downloads/Contrib/,Contrib directory of the @strong{MySQL} @uref{http://www.mysql.com/Downloads/Contrib/,Contrib directory of the @strong{MySQL}
Website}. Website}.
@node Passwords, Access denied, Adding users, Privilege system @node Passwords, Access denied, Adding users, Privilege system
@section How to set up passwords @section How to Set Up Passwords
@cindex Passwords, setting @cindex Passwords, setting
@findex PASSWORD() @findex PASSWORD()
...@@ -11953,14 +11954,13 @@ shell> mysqladmin -u jeffrey password biscuit ...@@ -11953,14 +11954,13 @@ shell> mysqladmin -u jeffrey password biscuit
@end example @end example
@strong{NOTE:} @code{PASSWORD()} does not perform password encryption in the @strong{NOTE:} @code{PASSWORD()} does not perform password encryption in the
same way that Unix passwords are encrypted. You should not assume that if same way that UNIX passwords are encrypted. You should not assume that if
your Unix password and your @strong{MySQL} password are the same, that your UNIX password and your @strong{MySQL} password are the same, that
@code{PASSWORD()} will result in the same encrypted value as is stored in the @code{PASSWORD()} will result in the same encrypted value as is stored in the
Unix password file. UNIX password file. @xref{User names}.
@xref{User names}.
@node Access denied, , Passwords, Privilege system @node Access denied, , Passwords, Privilege system
@section Causes of @code{Access denied} errors @section Causes of @code{Access denied} Errors
If you encounter @code{Access denied} errors when you try to connect to the If you encounter @code{Access denied} errors when you try to connect to the
@strong{MySQL} server, the list below indicates some courses of @strong{MySQL} server, the list below indicates some courses of
...@@ -12010,11 +12010,11 @@ host. ...@@ -12010,11 +12010,11 @@ host.
@item @item
@cindex @code{mysql_fix_privilege_tables} @cindex @code{mysql_fix_privilege_tables}
If you updated an existing @strong{MySQL} installation from a pre-3.22.11 If you updated an existing @strong{MySQL} installation from a version earlier
version to 3.22.11 or later, did you run the than Version 3.22.11 to Version 3.22.11 or later, did you run the
@code{mysql_fix_privilege_tables} script? If not, do so. The structure of @code{mysql_fix_privilege_tables} script? If not, do so. The structure of
the grant tables changed with @strong{MySQL} 3.22.11 when the @code{GRANT} the grant tables changed with @strong{MySQL} Version 3.22.11 when the
statement became functional. @code{GRANT} statement became functional.
@item @item
If your privileges seem to have changed in the middle of a session, it may be If your privileges seem to have changed in the middle of a session, it may be
...@@ -12025,7 +12025,7 @@ client connections, but it also affects existing connections as indicated in ...@@ -12025,7 +12025,7 @@ client connections, but it also affects existing connections as indicated in
@item @item
If you can't get your password to work, remember that you must use If you can't get your password to work, remember that you must use
the @code{PASSWORD()} function if you set the password with the the @code{PASSWORD()} function if you set the password with the
@code{INSERT}, @code{UPDATE} or @code{SET PASSWORD} statements. The @code{INSERT}, @code{UPDATE}, or @code{SET PASSWORD} statements. The
@code{PASSWORD()} function is unnecessary if you specify the password using @code{PASSWORD()} function is unnecessary if you specify the password using
the @code{GRANT ... INDENTIFIED BY} statement or the @code{mysqladmin the @code{GRANT ... INDENTIFIED BY} statement or the @code{mysqladmin
password} command. password} command.
...@@ -12036,7 +12036,7 @@ password} command. ...@@ -12036,7 +12036,7 @@ password} command.
default host to which clients try to connect if you specify no host default host to which clients try to connect if you specify no host
explicitly. However, connections to @code{localhost} do not work if you are explicitly. However, connections to @code{localhost} do not work if you are
running on a system that uses MIT-pthreads (@code{localhost} connections are running on a system that uses MIT-pthreads (@code{localhost} connections are
made using Unix sockets, which are not supported by MIT-pthreads). To avoid made using UNIX sockets, which are not supported by MIT-pthreads). To avoid
this problem on such systems, you should use the @code{--host} option to name this problem on such systems, you should use the @code{--host} option to name
the server host explicitly. This will make a TCP/IP connection to the the server host explicitly. This will make a TCP/IP connection to the
@code{mysqld} server. In this case, you must have your real hostname in @code{mysqld} server. In this case, you must have your real hostname in
...@@ -12074,11 +12074,11 @@ row in the @code{user} table that matches that host: ...@@ -12074,11 +12074,11 @@ row in the @code{user} table that matches that host:
Host ... is not allowed to connect to this MySQL server Host ... is not allowed to connect to this MySQL server
@end example @end example
You can fix this by using the command line tool @code{mysql} (on the You can fix this by using the command-line tool @code{mysql} (on the
server host!) to add a row to the @code{user}, @code{db} or @code{host} server host!) to add a row to the @code{user}, @code{db}, or @code{host}
table for the user/hostname combination from which you are trying to table for the user/hostname combination from which you are trying to
connect and then execute @code{mysqladmin flush-privileges}. If you are connect and then execute @code{mysqladmin flush-privileges}. If you are
not running @strong{MySQL} 3.22 and you don't know the IP number or not running @strong{MySQL} Version 3.22 and you don't know the IP number or
hostname of the machine from which you are connecting, you should put an hostname of the machine from which you are connecting, you should put an
entry with @code{'%'} as the @code{Host} column value in the @code{user} entry with @code{'%'} as the @code{Host} column value in the @code{user}
table and restart @code{mysqld} with the @code{--log} option on the table and restart @code{mysqld} with the @code{--log} option on the
...@@ -12109,7 +12109,7 @@ IP to a hostname. In this case you can execute @code{mysqladmin ...@@ -12109,7 +12109,7 @@ IP to a hostname. In this case you can execute @code{mysqladmin
flush-hosts} to reset the internal DNS cache. Some permanent solutions flush-hosts} to reset the internal DNS cache. Some permanent solutions
are: are:
@itemize @bullet @itemize @minus
@item @item
Try to find out what is wrong with your DNS server and fix this. Try to find out what is wrong with your DNS server and fix this.
@item @item
...@@ -12130,13 +12130,13 @@ If @code{mysql -u root test} works but @code{mysql -h your_hostname -u root ...@@ -12130,13 +12130,13 @@ If @code{mysql -u root test} works but @code{mysql -h your_hostname -u root
test} results in @code{Access denied}, then you may not have the correct name test} results in @code{Access denied}, then you may not have the correct name
for your host in the @code{user} table. A common problem here is that the for your host in the @code{user} table. A common problem here is that the
@code{Host} value in the user table entry specifies an unqualified hostname, @code{Host} value in the user table entry specifies an unqualified hostname,
but your system's name resolution routines return a fully-qualified domain but your system's name resolution routines return a fully qualified domain
name (or vice-versa). For example, if you have an entry with host name (or vice-versa). For example, if you have an entry with host
@code{'tcx'} in the @code{user} table, but your DNS tells @strong{MySQL} that @code{'tcx'} in the @code{user} table, but your DNS tells @strong{MySQL} that
your hostname is @code{'tcx.subnet.se'}, the entry will not work. Try adding your hostname is @code{'tcx.subnet.se'}, the entry will not work. Try adding
an entry to the @code{user} table that contains the IP number of your host as an entry to the @code{user} table that contains the IP number of your host as
the @code{Host} column value. (Alternatively, you could add an entry to the the @code{Host} column value. (Alternatively, you could add an entry to the
@code{user} table with a @code{Host} value that contains a wildcard---for @code{user} table with a @code{Host} value that contains a wild card---for
example, @code{'tcx.%'}. However, use of hostnames ending with @samp{%} is example, @code{'tcx.%'}. However, use of hostnames ending with @samp{%} is
@emph{insecure} and is @emph{not} recommended!) @emph{insecure} and is @emph{not} recommended!)
...@@ -12154,7 +12154,7 @@ in the @code{user} table or the @code{db} table. ...@@ -12154,7 +12154,7 @@ in the @code{user} table or the @code{db} table.
@item @item
If you can't figure out why you get @code{Access denied}, remove from the If you can't figure out why you get @code{Access denied}, remove from the
@code{user} table all entries that have @code{Host} values containing @code{user} table all entries that have @code{Host} values containing
wildcards (entries that contain @samp{%} or @samp{_}). A very common error wild cards (entries that contain @samp{%} or @samp{_}). A very common error
is to insert a new entry with @code{Host}=@code{'%'} and is to insert a new entry with @code{Host}=@code{'%'} and
@code{User}=@code{'some user'}, thinking that this will allow you to specify @code{User}=@code{'some user'}, thinking that this will allow you to specify
@code{localhost} to connect from the same machine. The reason that this @code{localhost} to connect from the same machine. The reason that this
...@@ -12201,7 +12201,7 @@ sure you haven't specified an old password in any of your option files! ...@@ -12201,7 +12201,7 @@ sure you haven't specified an old password in any of your option files!
@xref{Option files}. @xref{Option files}.
@item @item
If you make changes to the grant tables directly (using @code{INSERT} or If you make changes to the grant tables directly (using an @code{INSERT} or
@code{UPDATE} statement) and your changes seem to be ignored, remember @code{UPDATE} statement) and your changes seem to be ignored, remember
that you must issue a @code{FLUSH PRIVILEGES} statement or execute a that you must issue a @code{FLUSH PRIVILEGES} statement or execute a
@code{mysqladmin flush-privileges} command to cause the server to re-read @code{mysqladmin flush-privileges} command to cause the server to re-read
...@@ -12212,7 +12212,7 @@ specify it until after you flush the privileges, because the server ...@@ -12212,7 +12212,7 @@ specify it until after you flush the privileges, because the server
won't know you've changed the password yet! won't know you've changed the password yet!
@item @item
If you have access problems with a Perl, PHP, Python or ODBC program, try to If you have access problems with a Perl, PHP, Python, or ODBC program, try to
connect to the server with @code{mysql -u user_name db_name} or @code{mysql connect to the server with @code{mysql -u user_name db_name} or @code{mysql
-u user_name -pyour_pass db_name}. If you are able to connect using the -u user_name -pyour_pass db_name}. If you are able to connect using the
@code{mysql} client, there is a problem with your program and not with the @code{mysql} client, there is a problem with your program and not with the
...@@ -12244,12 +12244,12 @@ feel you must post the problem to the mailing list, always provide a ...@@ -12244,12 +12244,12 @@ feel you must post the problem to the mailing list, always provide a
dump of the @strong{MySQL} grant tables. You can dump the tables with dump of the @strong{MySQL} grant tables. You can dump the tables with
the @code{mysqldump mysql} command. As always, post your problem using the @code{mysqldump mysql} command. As always, post your problem using
the @code{mysqlbug} script. @xref{Bug reports}. In some cases you may need the @code{mysqlbug} script. @xref{Bug reports}. In some cases you may need
to restart @code{mysqld} with @code{--skip-grant-tables} to be able to run to restart @code{mysqld} with @code{--skip-grant-tables} to run
@code{mysqldump}. @code{mysqldump}.
@end itemize @end itemize
@node Reference, Table types, Privilege system, Top @node Reference, Table types, Privilege system, Top
@chapter MySQL language reference @chapter MySQL Language Reference
@menu @menu
* Literals:: Literals: how to write strings and numbers * Literals:: Literals: how to write strings and numbers
...@@ -12296,7 +12296,7 @@ to restart @code{mysqld} with @code{--skip-grant-tables} to be able to run ...@@ -12296,7 +12296,7 @@ to restart @code{mysqld} with @code{--skip-grant-tables} to be able to run
@cindex Strings @cindex Strings
@cindex Strings, escaping characters @cindex Strings, escaping characters
@node Literals, Variables, Reference, Reference @node Literals, Variables, Reference, Reference
@section Literals: how to write strings and numbers @section Literals: How to Write Strings and Numbers
@menu @menu
* String syntax:: Strings * String syntax:: Strings
...@@ -12365,19 +12365,19 @@ A double quote (@samp{"}) character. ...@@ -12365,19 +12365,19 @@ A double quote (@samp{"}) character.
@item \\ @item \\
A backslash (@samp{\}) character. A backslash (@samp{\}) character.
@findex % (wildcard character) @findex % (wild card character)
@findex Wildcard character (%) @findex Wild card character (%)
@item \% @item \%
A @samp{%} character. This is used to search for literal instances of A @samp{%} character. This is used to search for literal instances of
@samp{%} in contexts where @samp{%} would otherwise be interpreted @samp{%} in contexts where @samp{%} would otherwise be interpreted
as a wildcard character. @xref{String comparison functions}. as a wild card character. @xref{String comparison functions}.
@findex _ (wildcard character) @findex _ (wild card character)
@findex Wildcard character (_) @findex Wild card character (_)
@item \_ @item \_
A @samp{_} character. This is used to search for literal instances of A @samp{_} character. This is used to search for literal instances of
@samp{_} in contexts where @samp{_} would otherwise be interpreted @samp{_} in contexts where @samp{_} would otherwise be interpreted
as a wildcard character. @xref{String comparison functions}. as a wild card character. @xref{String comparison functions}.
@end table @end table
Note that if you use @samp{\%} or @samp{\_} in some string contexts, these Note that if you use @samp{\%} or @samp{\_} in some string contexts, these
...@@ -12483,11 +12483,11 @@ as the equivalent floating-point number. ...@@ -12483,11 +12483,11 @@ as the equivalent floating-point number.
@tindex Hexadecimal values @tindex Hexadecimal values
@node Hexadecimal values, NULL values, Number syntax, Literals @node Hexadecimal values, NULL values, Number syntax, Literals
@subsection Hexadecimal values @subsection Hexadecimal Values
@strong{MySQL} supports hexadecimal values. In number context these acts @strong{MySQL} supports hexadecimal values. In number context these act
like an integer (64 bit precision). In string context these acts like a binary like an integer (64-bit precision). In string context these act like a binary
string where each pair of hex digits is converted to a character. string where each pair of hex digits is converted to a character:
@example @example
mysql> SELECT 0xa+0 mysql> SELECT 0xa+0
...@@ -12496,11 +12496,11 @@ mysql> select 0x5061756c; ...@@ -12496,11 +12496,11 @@ mysql> select 0x5061756c;
-> Paul -> Paul
@end example @end example
Hexadecimal strings is often used by ODBC to give values for BLOB columns. Hexadecimal strings are often used by ODBC to give values for BLOB columns.
@tindex NULL value @tindex NULL value
@node NULL values, Legal names, Hexadecimal values, Literals @node NULL values, Legal names, Hexadecimal values, Literals
@subsection @code{NULL} values @subsection @code{NULL} Values
The @code{NULL} value means ``no data'' and is different from values such The @code{NULL} value means ``no data'' and is different from values such
as @code{0} for numeric types or the empty string for string types. as @code{0} for numeric types or the empty string for string types.
...@@ -12511,35 +12511,35 @@ or export formats (@code{LOAD DATA INFILE}, @code{SELECT ... INTO OUTFILE}). ...@@ -12511,35 +12511,35 @@ or export formats (@code{LOAD DATA INFILE}, @code{SELECT ... INTO OUTFILE}).
@xref{LOAD DATA, , @code{LOAD DATA}}. @xref{LOAD DATA, , @code{LOAD DATA}}.
@node Legal names, , NULL values, Literals @node Legal names, , NULL values, Literals
@subsection Database, table, index, column and alias names @subsection Database, Table, Index, Column, and Alias Names
@menu @menu
* Name case sensitivity:: Case sensitivity in names * Name case sensitivity:: Case sensitivity in names
@end menu @end menu
Database, table, index, column and alias names all follow the same rules in Database, table, index, column, and alias names all follow the same rules in
@strong{MySQL}: @strong{MySQL}.
@tindex Quoting of identifiers @tindex Quoting of identifiers
@tindex ` @tindex `
@tindex " @tindex "
Note that the rules changed starting with @strong{MySQL} 3.23.6 when we Note that the rules changed starting with @strong{MySQL} Version 3.23.6 when we
introduced quoting of identifiers (database, table and column names) introduced quoting of identifiers (database, table, and column names)
with @samp{`} (@samp{"} will also work to quote identifiers if you run with @samp{`} (@samp{"} will also work to quote identifiers if you run
in ANSI mode). in ANSI mode).
@multitable @columnfractions .15 .15 .70 @multitable @columnfractions .15 .15 .70
@item @strong{Identifier} @tab @strong{Max length} @tab @strong{Allowed characters} @item @strong{Identifier} @tab @strong{Max length} @tab @strong{Allowed characters}
@item Database @tab 64 @tab Any character that is allowed in a directory name except @code{/}. @item Database @tab 64 @tab Any character that is allowed in a directory name except @samp{/}.
@item Table @tab 64 @tab Any character that is allowed in file name, except @code{/} or @code{.} @item Table @tab 64 @tab Any character that is allowed in a file name, except @samp{/} or @samp{.}.
@item Column @tab 64 @tab All characters @item Column @tab 64 @tab All characters.
@item Alias @tab 255 @tab All characters @item Alias @tab 255 @tab All characters.
@end multitable @end multitable
Note that in addition to the above, you can't have ASCII(0) or ASCII(255) in Note that in addition to the above, you can't have ASCII(0) or ASCII(255) in
an identifier. an identifier.
Note that if the identifer is a restricted word or contains special character Note that if the identifer is a restricted word or contains special characters
you must always quote it with @code{`} when you use it: you must always quote it with @code{`} when you use it:
@example @example
...@@ -12580,7 +12580,7 @@ from whichever table used in the query contains a column of that name ...@@ -12580,7 +12580,7 @@ from whichever table used in the query contains a column of that name
@code{tbl_name} of the current database @code{tbl_name} of the current database
@item @code{db_name.tbl_name.col_name} @tab Column @code{col_name} from table @item @code{db_name.tbl_name.col_name} @tab Column @code{col_name} from table
@code{tbl_name} of the database @code{db_name}. This form is available in @code{tbl_name} of the database @code{db_name}. This form is available in
@strong{MySQL} 3.22 or later. @strong{MySQL} Version 3.22 or later.
@item @item
@code{`column_name`} @tab A column that is a keyword or contains special characters. @code{`column_name`} @tab A column that is a keyword or contains special characters.
@end multitable @end multitable
...@@ -12603,7 +12603,7 @@ database. This syntax is accepted for ODBC compatibility, because some ODBC ...@@ -12603,7 +12603,7 @@ database. This syntax is accepted for ODBC compatibility, because some ODBC
programs prefix table names with a @samp{.} character. programs prefix table names with a @samp{.} character.
@node Name case sensitivity, , Legal names, Legal names @node Name case sensitivity, , Legal names, Legal names
@subsubsection Case sensitivity in names @subsubsection Case Sensitivity in Names
@cindex Database names, case sensitivity @cindex Database names, case sensitivity
@cindex Table names, case sensitivity @cindex Table names, case sensitivity
@cindex Column names, case sensitivity @cindex Column names, case sensitivity
...@@ -12616,10 +12616,10 @@ programs prefix table names with a @samp{.} character. ...@@ -12616,10 +12616,10 @@ programs prefix table names with a @samp{.} character.
In @strong{MySQL}, databases and tables correspond to directories and files In @strong{MySQL}, databases and tables correspond to directories and files
within those directories. Consequently, the case sensitivity of the within those directories. Consequently, the case sensitivity of the
underlying operating system determines the case sensitivity of database and underlying operating system determines the case sensitivity of database and
table names. This means database and table names are case sensitive in Unix table names. This means database and table names are case sensitive in UNIX
and case insensitive in Windows. and case insensitive in Windows.
@strong{Note:} Although database and table names are case insensitive for @strong{NOTE:} Although database and table names are case insensitive for
Windows, you should not refer to a given database or table using different Windows, you should not refer to a given database or table using different
cases within the same query. The following query would not work because it cases within the same query. The following query would not work because it
refers to a table both as @code{my_table} and as @code{MY_TABLE}: refers to a table both as @code{my_table} and as @code{MY_TABLE}:
...@@ -12641,9 +12641,9 @@ mysql> SELECT col_name FROM tbl_name AS a ...@@ -12641,9 +12641,9 @@ mysql> SELECT col_name FROM tbl_name AS a
Aliases on columns are case insensitive. Aliases on columns are case insensitive.
@node Variables, Column types, Literals, Reference @node Variables, Column types, Literals, Reference
@section User variables @section User Variables
@strong{MySQL} supports thread specific variables with the @strong{MySQL} supports thread-specific variables with the
@code{@@variablename} syntax. A variable name may consist of @code{@@variablename} syntax. A variable name may consist of
alphanumeric characters from the current character set and also alphanumeric characters from the current character set and also
@samp{_}, @samp{$}, and @samp{.} . The default character set is @samp{_}, @samp{$}, and @samp{.} . The default character set is
...@@ -12652,7 +12652,7 @@ ISO-8859-1 Latin1; this may be changed with the ...@@ -12652,7 +12652,7 @@ ISO-8859-1 Latin1; this may be changed with the
sets}. sets}.
Variables don't have to be initialized. They contain @code{NULL} by default Variables don't have to be initialized. They contain @code{NULL} by default
and can store an integer, real or string value. All variables for and can store an integer, real, or string value. All variables for
a thread are automatically freed when the thread exits. a thread are automatically freed when the thread exits.
You can set a variable with the @code{SET} syntax: You can set a variable with the @code{SET} syntax:
...@@ -12683,10 +12683,10 @@ required, such as in the @code{LIMIT} clause of a @code{SELECT} statement, ...@@ -12683,10 +12683,10 @@ required, such as in the @code{LIMIT} clause of a @code{SELECT} statement,
or the @code{IGNORE number LINES} clause of a @code{LOAD DATA} statement. or the @code{IGNORE number LINES} clause of a @code{LOAD DATA} statement.
@strong{NOTE:} In a @code{SELECT} statement, each expression is only @strong{NOTE:} In a @code{SELECT} statement, each expression is only
evaluated when it's sent to the client. This means that one can't evaluated when it's sent to the client. This means that in the @code{HAVING},
in the @code{HAVING}, @code{GROUP BY} or @code{ORDER BY} clause refer to an @code{GROUP BY}, or @code{ORDER BY} clause, you can't refer to an expression
expression that involves variables that are set in the @code{SELECT} part. that involves variables that are set in the @code{SELECT} part. For example,
For example, the following statement will NOT work as expected: the following statement will NOT work as expected:
@example @example
SELECT (@@aa:=id) AS a, (@@aa+3) AS b FROM table_name HAVING b=5; SELECT (@@aa:=id) AS a, (@@aa+3) AS b FROM table_name HAVING b=5;
...@@ -12696,7 +12696,7 @@ The reason is that @code{@@aa} will not contain the value of the current ...@@ -12696,7 +12696,7 @@ The reason is that @code{@@aa} will not contain the value of the current
row, but the value of @code{id} for the previous accepted row. row, but the value of @code{id} for the previous accepted row.
@node Column types, Functions, Variables, Reference @node Column types, Functions, Variables, Reference
@section Column types @section Column Types
@strong{MySQL} supports a number of column types, which may be grouped into @strong{MySQL} supports a number of column types, which may be grouped into
three categories: numeric types, date and time types, and string (character) three categories: numeric types, date and time types, and string (character)
...@@ -12769,7 +12769,7 @@ A large integer. The signed range is @code{-9223372036854775808} to ...@@ -12769,7 +12769,7 @@ A large integer. The signed range is @code{-9223372036854775808} to
@code{18446744073709551615}. Note that all arithmetic is done using @code{18446744073709551615}. Note that all arithmetic is done using
signed @code{BIGINT} or @code{DOUBLE} values, so you shouldn't use signed @code{BIGINT} or @code{DOUBLE} values, so you shouldn't use
unsigned big integers larger than @code{9223372036854775807} (63 bits) unsigned big integers larger than @code{9223372036854775807} (63 bits)
except with bit functions! Note that @code{-}, @code{+} and @code{*} except with bit functions! Note that @samp{-}, @samp{+}, and @samp{*}
will use @code{BIGINT} arithmetic when both arguments are @code{INTEGER} will use @code{BIGINT} arithmetic when both arguments are @code{INTEGER}
values! This means that if you multiply two big integers (or results values! This means that if you multiply two big integers (or results
from functions that return integers) you may get unexpected results if from functions that return integers) you may get unexpected results if
...@@ -12780,14 +12780,13 @@ the result is larger than @code{9223372036854775807}. ...@@ -12780,14 +12780,13 @@ the result is larger than @code{9223372036854775807}.
@item FLOAT(precision) [ZEROFILL] @item FLOAT(precision) [ZEROFILL]
A floating-point number. Cannot be unsigned. @code{precision} can be A floating-point number. Cannot be unsigned. @code{precision} can be
@code{<=24} for a single precision floating point number and between 25 @code{<=24} for a single-precision floating-point number and between 25
and 53 for a double precision floating point number. and 53 for a double-precision floating-point number. These types are like
these types are like the @code{FLOAT} and @code{DOUBLE} types described the @code{FLOAT} and @code{DOUBLE} types described immediately below.
immediately below. @code{FLOAT(X)} have the same ranges as the @code{FLOAT(X)} has the same range as the corresponding @code{FLOAT} and
corresponding @code{FLOAT} and @code{DOUBLE} types, but the display @code{DOUBLE} types, but the display size and number of decimals is undefined.
size and number of decimals is undefined.
In @strong{MySQL} Version 3.23, this is a true floating-point value. In
In @strong{MySQL} 3.23, this is a true floating point value. In
earlier @strong{MySQL} versions, @code{FLOAT(precision)} always has 2 decimals. earlier @strong{MySQL} versions, @code{FLOAT(precision)} always has 2 decimals.
@cindex ODBC compatibility @cindex ODBC compatibility
...@@ -12800,10 +12799,10 @@ This syntax is provided for ODBC compatibility. ...@@ -12800,10 +12799,10 @@ This syntax is provided for ODBC compatibility.
A small (single-precision) floating-point number. Cannot be unsigned. A small (single-precision) floating-point number. Cannot be unsigned.
Allowable values are @code{@w{-3.402823466E+38}} to Allowable values are @code{@w{-3.402823466E+38}} to
@code{@w{-1.175494351E-38}}, @code{0} and @code{@w{1.175494351E-38}} to @code{@w{-1.175494351E-38}}, @code{0}, and @code{@w{1.175494351E-38}} to
@code{3.402823466E+38}. The M is the display width and D is the @code{3.402823466E+38}. The M is the display width and D is the
number of decimals. @code{FLOAT} without an argument or with an argument of number of decimals. @code{FLOAT} without an argument or with an argument of
<= 24 stands for a single-precision floating point number. <= 24 stands for a single-precision floating-point number.
@tindex DOUBLE @tindex DOUBLE
@tindex FLOAT(precision) @tindex FLOAT(precision)
...@@ -12811,11 +12810,11 @@ number of decimals. @code{FLOAT} without an argument or with an argument of ...@@ -12811,11 +12810,11 @@ number of decimals. @code{FLOAT} without an argument or with an argument of
A normal-size (double-precision) floating-point number. Cannot be A normal-size (double-precision) floating-point number. Cannot be
unsigned. Allowable values are @code{@w{-1.7976931348623157E+308}} to unsigned. Allowable values are @code{@w{-1.7976931348623157E+308}} to
@code{@w{-2.2250738585072014E-308}}, @code{0} and @code{@w{-2.2250738585072014E-308}}, @code{0}, and
@code{2.2250738585072014E-308} to @code{1.7976931348623157E+308}. The M @code{2.2250738585072014E-308} to @code{1.7976931348623157E+308}. The M
is the display width and D is the number of decimals. @code{DOUBLE} is the display width and D is the number of decimals. @code{DOUBLE}
without an argument or @code{FLOAT(X)} where 25 <= X <= 53 stands for a without an argument or @code{FLOAT(X)} where 25 <= X <= 53 stands for a
double-precision floating point number. double-precision floating-point number.
@tindex DOUBLE PRECISION @tindex DOUBLE PRECISION
@tindex REAL @tindex REAL
...@@ -12829,8 +12828,8 @@ These are synonyms for @code{DOUBLE}. ...@@ -12829,8 +12828,8 @@ These are synonyms for @code{DOUBLE}.
An unpacked floating-point number. Cannot be unsigned. Behaves like a An unpacked floating-point number. Cannot be unsigned. Behaves like a
@code{CHAR} column: ``unpacked'' means the number is stored as a string, @code{CHAR} column: ``unpacked'' means the number is stored as a string,
using one character for each digit of the value. The decimal point, using one character for each digit of the value. The decimal point
and, for negative numbers, the @samp{-} sign is not counted in M. If and, for negative numbers, the @samp{-} sign, are not counted in M. If
@code{D} is 0, values will have no decimal point or fractional part. @code{D} is 0, values will have no decimal point or fractional part.
The maximum range of @code{DECIMAL} values is the same as for The maximum range of @code{DECIMAL} values is the same as for
@code{DOUBLE}, but the actual range for a given @code{DECIMAL} column @code{DOUBLE}, but the actual range for a given @code{DECIMAL} column
...@@ -12838,8 +12837,8 @@ may be constrained by the choice of @code{M} and @code{D}. ...@@ -12838,8 +12837,8 @@ may be constrained by the choice of @code{M} and @code{D}.
If @code{D} is left out it's set to 0. If @code{M} is left out it's set to 10. If @code{D} is left out it's set to 0. If @code{M} is left out it's set to 10.
Note that in @strong{MySQL} 3.22 the @code{M} argument includes the sign Note that in @strong{MySQL} Version 3.22 the @code{M} argument includes the
and the decimal point. sign and the decimal point.
@tindex NUMERIC @tindex NUMERIC
@item NUMERIC(M,D) [ZEROFILL] @item NUMERIC(M,D) [ZEROFILL]
...@@ -12867,7 +12866,7 @@ to assign values to @code{DATETIME} columns using either strings or numbers. ...@@ -12867,7 +12866,7 @@ to assign values to @code{DATETIME} columns using either strings or numbers.
A timestamp. The range is @code{'1970-01-01 00:00:00'} to sometime in the A timestamp. The range is @code{'1970-01-01 00:00:00'} to sometime in the
year @code{2037}. @strong{MySQL} displays @code{TIMESTAMP} values in year @code{2037}. @strong{MySQL} displays @code{TIMESTAMP} values in
@code{YYYYMMDDHHMMSS}, @code{YYMMDDHHMMSS}, @code{YYYYMMDD} or @code{YYMMDD} @code{YYYYMMDDHHMMSS}, @code{YYMMDDHHMMSS}, @code{YYYYMMDD}, or @code{YYMMDD}
format, depending on whether @code{M} is @code{14} (or missing), @code{12}, format, depending on whether @code{M} is @code{14} (or missing), @code{12},
@code{8} or @code{6}, but allows you to assign values to @code{TIMESTAMP} @code{8} or @code{6}, but allows you to assign values to @code{TIMESTAMP}
columns using either strings or numbers. A @code{TIMESTAMP} column is useful columns using either strings or numbers. A @code{TIMESTAMP} column is useful
...@@ -12877,12 +12876,12 @@ recent operation if you don't give it a value yourself. You can also set it ...@@ -12877,12 +12876,12 @@ recent operation if you don't give it a value yourself. You can also set it
to the current date and time by assigning it a @code{NULL} value. @xref{Date to the current date and time by assigning it a @code{NULL} value. @xref{Date
and time types}. and time types}.
A @code{TIMESTAMP} is always stored in 4 bytes; The @code{M} argument only A @code{TIMESTAMP} is always stored in 4 bytes. The @code{M} argument only
affects how the @code{TIMESTAMP} column is displayed. affects how the @code{TIMESTAMP} column is displayed.
Note that @code{TIMESTAMP(X)} columns where X is 8 or 14 are reported to Note that @code{TIMESTAMP(X)} columns where X is 8 or 14 are reported to
be numbers while other @code{TIMESTAMP(X)} columns are reported to be be numbers while other @code{TIMESTAMP(X)} columns are reported to be
strings. This is just to ensure that one can reliable dump and restore strings. This is just to ensure that one can reliably dump and restore
the table with these types! the table with these types!
@tindex TIME @tindex TIME
...@@ -12896,12 +12895,12 @@ numbers. ...@@ -12896,12 +12895,12 @@ numbers.
@tindex YEAR @tindex YEAR
@item YEAR[(2|4)] @item YEAR[(2|4)]
A year in 2- or 4- digit formats (default is 4-digit). The allowable values are A year in 2- or 4- digit formats (default is 4-digit). The allowable values
@code{1901} to @code{2155}, and @code{0000} in the 4 year format and are @code{1901} to @code{2155}, and @code{0000} in the 4-digit year format,
1970-2069 if you use the 2 digit format (70-69). @strong{MySQL} displays and 1970-2069 if you use the 2-digit format (70-69). @strong{MySQL} displays
@code{YEAR} values in @code{YYYY} format, but allows you to assign @code{YEAR} values in @code{YYYY} format, but allows you to assign values to
values to @code{YEAR} columns using either strings or numbers. @code{YEAR} columns using either strings or numbers. (The @code{YEAR} type is
(The @code{YEAR} type is new in @strong{MySQL} 3.22.) new in @strong{MySQL} Version 3.22.)
@tindex NATIONAL CHAR @tindex NATIONAL CHAR
@tindex NCHAR @tindex NCHAR
...@@ -12917,7 +12916,7 @@ default character set unless the @code{BINARY} keyword is given. ...@@ -12917,7 +12916,7 @@ default character set unless the @code{BINARY} keyword is given.
@code{NATIONAL CHAR} (short form @code{NCHAR}) is the ANSI SQL way to @code{NATIONAL CHAR} (short form @code{NCHAR}) is the ANSI SQL way to
define that a CHAR column should use the default CHARACTER set. This is define that a CHAR column should use the default CHARACTER set. This is
default in @strong{MySQL}. the default in @strong{MySQL}.
@code{CHAR} is a shorthand for @code{CHARACTER}. @code{CHAR} is a shorthand for @code{CHARACTER}.
...@@ -12934,11 +12933,11 @@ as @code{NOT NULL}, will only occupy one bit and can only take 2 values: ...@@ -12934,11 +12933,11 @@ as @code{NOT NULL}, will only occupy one bit and can only take 2 values:
@tindex VARCHAR @tindex VARCHAR
@item [NATIONAL] VARCHAR(M) [BINARY] @item [NATIONAL] VARCHAR(M) [BINARY]
A variable-length string. Note: A variable-length string. @strong{NOTE:} Trailing spaces are removed when
Trailing spaces are removed when the value is stored (this differs from the the value is stored (this differs from the ANSI SQL specification). The range
ANSI SQL specification). The range of @code{M} is 1 to 255 characters. of @code{M} is 1 to 255 characters. @code{VARCHAR} values are sorted and
@code{VARCHAR} values are sorted and compared in case-insensitive fashion compared in case-insensitive fashion unless the @code{BINARY} keyword is
unless the @code{BINARY} keyword is given. @xref{Silent column changes}. given. @xref{Silent column changes}.
@code{VARCHAR} is a shorthand for @code{CHARACTER VARYING}. @code{VARCHAR} is a shorthand for @code{CHARACTER VARYING}.
...@@ -13003,14 +13002,14 @@ be chosen from the list of values @code{'value1'}, @code{'value2'}, ...@@ -13003,14 +13002,14 @@ be chosen from the list of values @code{'value1'}, @code{'value2'},
@cindex Storage requirements @cindex Storage requirements
@node Storage requirements, Numeric types, Column types, Column types @node Storage requirements, Numeric types, Column types, Column types
@subsection Column type storage requirements @subsection Column Type Storage Requirements
The storage requirements for each of the column types supported by The storage requirements for each of the column types supported by
@strong{MySQL} are listed below by category. @strong{MySQL} are listed below by category.
@subheading Numeric types @subheading Numeric types
@multitable @columnfractions .35 .65 @multitable @columnfractions .5 .5
@item @strong{Column type} @tab @strong{Storage required} @item @strong{Column type} @tab @strong{Storage required}
@item @code{TINYINT} @tab 1 byte @item @code{TINYINT} @tab 1 byte
@item @code{SMALLINT} @tab 2 bytes @item @code{SMALLINT} @tab 2 bytes
...@@ -13029,7 +13028,7 @@ The storage requirements for each of the column types supported by ...@@ -13029,7 +13028,7 @@ The storage requirements for each of the column types supported by
@subheading Date and time types @subheading Date and time types
@multitable @columnfractions .35 .65 @multitable @columnfractions .5 .5
@item @strong{Column type} @tab @strong{Storage required} @item @strong{Column type} @tab @strong{Storage required}
@item @code{DATE} @tab 3 bytes @item @code{DATE} @tab 3 bytes
@item @code{DATETIME} @tab 8 bytes @item @code{DATETIME} @tab 8 bytes
...@@ -13040,7 +13039,7 @@ The storage requirements for each of the column types supported by ...@@ -13040,7 +13039,7 @@ The storage requirements for each of the column types supported by
@subheading String types @subheading String types
@multitable @columnfractions .35 .65 @multitable @columnfractions .5 .5
@item @strong{Column type} @tab @strong{Storage required} @item @strong{Column type} @tab @strong{Storage required}
@item @code{CHAR(M)} @tab @code{M} bytes, @code{1 <= M <= 255} @item @code{CHAR(M)} @tab @code{M} bytes, @code{1 <= M <= 255}
@item @code{VARCHAR(M)} @tab @code{L}+1 bytes, where @code{L <= M} and @item @code{VARCHAR(M)} @tab @code{L}+1 bytes, where @code{L <= M} and
...@@ -13068,26 +13067,26 @@ storage required is the length of the string (@code{L}), plus 1 byte to ...@@ -13068,26 +13067,26 @@ storage required is the length of the string (@code{L}), plus 1 byte to
record the length of the string. For the string @code{'abcd'}, @code{L} is 4 record the length of the string. For the string @code{'abcd'}, @code{L} is 4
and the storage requirement is 5 bytes. and the storage requirement is 5 bytes.
The @code{BLOB} and @code{TEXT} types require 1, 2, 3 or 4 bytes to record The @code{BLOB} and @code{TEXT} types require 1, 2, 3, or 4 bytes to record
the length of the column value, depending on the maximum possible length of the length of the column value, depending on the maximum possible length of
the type. the type.
If a table includes any variable-length column types, the record format will If a table includes any variable-length column types, the record format will
also be variable-length. Note that when a table is created, @strong{MySQL} also be variable-length. Note that when a table is created, @strong{MySQL}
may under certain conditions change a column from a variable-length type to a may, under certain conditions, change a column from a variable-length type to a
fixed-length type, or vice-versa. @xref{Silent column changes}. fixed-length type, or vice-versa. @xref{Silent column changes}.
The size of an @code{ENUM} object is determined by the number of different The size of an @code{ENUM} object is determined by the number of different
enumeration values. 1 byte is used for enumerations with up to 255 possible enumeration values. One byte is used for enumerations with up to 255 possible
values. 2 bytes are used for enumerations with up to 65535 values. values. Two bytes are used for enumerations with up to 65535 values.
The size of a @code{SET} object is determined by the number of different The size of a @code{SET} object is determined by the number of different
set members. If the set size is @code{N}, the object occupies @code{(N+7)/8} set members. If the set size is @code{N}, the object occupies @code{(N+7)/8}
bytes, rounded up to 1, 2, 3, 4 or 8 bytes. A @code{SET} can have a maximum bytes, rounded up to 1, 2, 3, 4, or 8 bytes. A @code{SET} can have a maximum
of 64 members. of 64 members.
@node Numeric types, Date and time types, Storage requirements, Column types @node Numeric types, Date and time types, Storage requirements, Column types
@subsection Numeric types @subsection Numeric Types
@strong{MySQL} supports all of the ANSI/ISO SQL92 numeric types. These @strong{MySQL} supports all of the ANSI/ISO SQL92 numeric types. These
types include the exact numeric data types (@code{NUMERIC}, types include the exact numeric data types (@code{NUMERIC},
...@@ -13109,10 +13108,10 @@ example: ...@@ -13109,10 +13108,10 @@ example:
@end example @end example
In this example, @code{9} (@code{precision}) represents the number of In this example, @code{9} (@code{precision}) represents the number of
significant decimal digits which will be stored for values, and significant decimal digits that will be stored for values, and
@code{2} (@code{scale}) represents the number of digits which will be @code{2} (@code{scale}) represents the number of digits that will be
stored following the decimal point. In this case, therefore, the range stored following the decimal point. In this case, therefore, the range
of values which can be stored in the @code{salary} column is from of values that can be stored in the @code{salary} column is from
@code{-9999999.99} to @code{9999999.99}. In ANSI/ISO SQL92, the syntax @code{-9999999.99} to @code{9999999.99}. In ANSI/ISO SQL92, the syntax
@code{DECIMAL(p)} is equivalent to @code{DECIMAL(p,0)}. Similarly, the @code{DECIMAL(p)} is equivalent to @code{DECIMAL(p,0)}. Similarly, the
syntax @code{DECIMAL} is equivalent to @code{DECIMAL(p,0)}, where the syntax @code{DECIMAL} is equivalent to @code{DECIMAL(p,0)}, where the
...@@ -13125,7 +13124,7 @@ the ability to control both precision and scale explicitly. ...@@ -13125,7 +13124,7 @@ the ability to control both precision and scale explicitly.
@code{DECIMAL} and @code{NUMERIC} values are stored as strings, rather @code{DECIMAL} and @code{NUMERIC} values are stored as strings, rather
than as binary floating point numbers, in order to preserve the decimal than as binary floating point numbers, in order to preserve the decimal
precision of those values. One character is used for each digit of the precision of those values. One character is used for each digit of the
value, the decimal point (if @code{scale} > 0) and the @samp{-} sign value, the decimal point (if @code{scale} > 0), and the @samp{-} sign
(for negative numbers). If @code{scale} is 0, @code{DECIMAL} and (for negative numbers). If @code{scale} is 0, @code{DECIMAL} and
@code{NUMERIC} values contain no decimal point or fractional part. @code{NUMERIC} values contain no decimal point or fractional part.
...@@ -13149,16 +13148,16 @@ of an integral value in parentheses following the base keyword for the ...@@ -13149,16 +13148,16 @@ of an integral value in parentheses following the base keyword for the
type (for example, @code{INT(4)}). This optional width specification is type (for example, @code{INT(4)}). This optional width specification is
used to left-pad the display of values whose width is less than the used to left-pad the display of values whose width is less than the
width specified for the column, but does not constrain the range of width specified for the column, but does not constrain the range of
values which can be stored in the column, nor the number of digits which values which can be stored in the column, nor the number of digits that
will be displayed for values whose width exceeds that specified for the will be displayed for values whose width exceeds that specified for the
column. When used in conjunction with the optional extension attribute column. When used in conjunction with the optional extension attribute
@code{ZEROFILL} the default padding of spaces is replaced with zeroes. @code{ZEROFILL}, the default padding of spaces is replaced with zeroes.
For example, for a column declared as @code{INT(5) ZEROFILL}, a value For example, for a column declared as @code{INT(5) ZEROFILL}, a value
of @code{4} is retrieved as @code{00004}. Note that if you store larger of @code{4} is retrieved as @code{00004}. Note that if you store larger
values than the display width in an integral column, you may experience values than the display width in an integer column, you may experience
problems when @strong{MySQL} generates temporary tables for some problems when @strong{MySQL} generates temporary tables for some
complicated joins as in these case @strong{MySQL} trust that the data complicated joins, as in these cases @strong{MySQL} will trust that the
did fit into the original column width. data did fit into the original column width.
All integral types can have an optional (non-standard) attribute All integral types can have an optional (non-standard) attribute
@code{UNSIGNED}. Unsigned values can be used when you want to allow @code{UNSIGNED}. Unsigned values can be used when you want to allow
...@@ -13188,7 +13187,7 @@ standard, @strong{MySQL} recognizes @code{DOUBLE} as a synonym for the ...@@ -13188,7 +13187,7 @@ standard, @strong{MySQL} recognizes @code{DOUBLE} as a synonym for the
@code{DOUBLE PRECISION} type. In contrast with the standard's @code{DOUBLE PRECISION} type. In contrast with the standard's
requirement that the precision for @code{REAL} be smaller than that used requirement that the precision for @code{REAL} be smaller than that used
for @code{DOUBLE PRECISION}, @strong{MySQL} implements both as 8-byte for @code{DOUBLE PRECISION}, @strong{MySQL} implements both as 8-byte
double-precision floating point values (when not running in ``Ansi mode''). double-precision floating-point values (when not running in ``Ansi mode'').
For maximum portability, code requiring storage of approximate numeric For maximum portability, code requiring storage of approximate numeric
data values should use @code{FLOAT} or @code{DOUBLE PRECISION} with no data values should use @code{FLOAT} or @code{DOUBLE PRECISION} with no
specification of precision or number of decimal points. specification of precision or number of decimal points.
...@@ -13209,13 +13208,13 @@ If you try to store @code{-9999999999} and @code{9999999999}, ...@@ -13209,13 +13208,13 @@ If you try to store @code{-9999999999} and @code{9999999999},
the values stored in the column become @code{0} and @code{4294967296}. the values stored in the column become @code{0} and @code{4294967296}.
Conversions that occur due to clipping are reported as ``warnings'' for Conversions that occur due to clipping are reported as ``warnings'' for
@code{ALTER TABLE}, @code{LOAD DATA INFILE}, @code{UPDATE} and @code{ALTER TABLE}, @code{LOAD DATA INFILE}, @code{UPDATE}, and
multi-row @code{INSERT} statements. multi-row @code{INSERT} statements.
@cindex Types, Date and Time @cindex Types, Date and Time
@cindex Date and Time types @cindex Date and Time types
@node Date and time types, String types, Numeric types, Column types @node Date and time types, String types, Numeric types, Column types
@subsection Date and time types @subsection Date and Time Types
@menu @menu
* Y2K issues:: Y2K issues and date types * Y2K issues:: Y2K issues and date types
...@@ -13225,7 +13224,7 @@ multi-row @code{INSERT} statements. ...@@ -13225,7 +13224,7 @@ multi-row @code{INSERT} statements.
@end menu @end menu
The date and time types are @code{DATETIME}, @code{DATE}, The date and time types are @code{DATETIME}, @code{DATE},
@code{TIMESTAMP}, @code{TIME} and @code{YEAR}. Each of these has a @code{TIMESTAMP}, @code{TIME}, and @code{YEAR}. Each of these has a
range of legal values, as well as a ``zero'' value that is used when you range of legal values, as well as a ``zero'' value that is used when you
specify a really illegal value. Note that @strong{MySQL} allows you to store specify a really illegal value. Note that @strong{MySQL} allows you to store
certain 'not strictly' legal date values, for example @code{1999-11-31}. certain 'not strictly' legal date values, for example @code{1999-11-31}.
...@@ -13235,11 +13234,11 @@ date checking 'fast', @strong{MySQL} only checks that the month is in ...@@ -13235,11 +13234,11 @@ date checking 'fast', @strong{MySQL} only checks that the month is in
the range of 0-12 and the day is in the range of 0-31. The above ranges the range of 0-12 and the day is in the range of 0-31. The above ranges
are defined this way because @strong{MySQL} allows you to store, in a are defined this way because @strong{MySQL} allows you to store, in a
@code{DATE} or @code{DATETIME} column, dates where the day or month-day @code{DATE} or @code{DATETIME} column, dates where the day or month-day
are zero. This is extremely useful for applications that need to store is zero. This is extremely useful for applications that need to store
a birth-date for which you don't know the exact date. In this case you a birth-date for which you don't know the exact date. In this case you
simply store the date like @code{1999-00-00} or @code{1999-01-00}. (You simply store the date like @code{1999-00-00} or @code{1999-01-00}. (You
can of course not expect to get a correct value from functions like cannot expect to get a correct value from functions like @code{DATE_SUB()}
@code{DATE_SUB()} or @code{DATE_ADD} for dates like these). or @code{DATE_ADD} for dates like these.)
Here are some general considerations to keep in mind when working Here are some general considerations to keep in mind when working
with date and time types: with date and time types:
...@@ -13248,18 +13247,18 @@ with date and time types: ...@@ -13248,18 +13247,18 @@ with date and time types:
@item @item
@strong{MySQL} retrieves values for a given date or time type in a standard @strong{MySQL} retrieves values for a given date or time type in a standard
format, but it attempts to interpret a variety of formats for values that format, but it attempts to interpret a variety of formats for values that
you supply (e.g., when you specify a value to be assigned to or compared to a you supply (for example, when you specify a value to be assigned to or
date or time type). Nevertheless, only the formats described in the compared to a date or time type). Nevertheless, only the formats described
following sections are supported. It is expected that you will supply legal in the following sections are supported. It is expected that you will supply
values, and unpredictable results may occur if you use values in other legal values, and unpredictable results may occur if you use values in other
formats. formats.
@item @item
Although @strong{MySQL} tries to interpret values in several formats, it Although @strong{MySQL} tries to interpret values in several formats, it
always expects the year part of date values to be leftmost. Dates must be always expects the year part of date values to be leftmost. Dates must be
given in year-month-day order (e.g., @code{'98-09-04'}), rather than in the given in year-month-day order (for example, @code{'98-09-04'}), rather than
month-day-year or day-month-year orders commonly used elsewhere (e.g., in the month-day-year or day-month-year orders commonly used elsewhere (for
@code{'09-04-98'}, @code{'04-09-98'}). example, @code{'09-04-98'}, @code{'04-09-98'}).
@item @item
@strong{MySQL} automatically converts a date or time type value to a number @strong{MySQL} automatically converts a date or time type value to a number
...@@ -13267,7 +13266,7 @@ if the value is used in a numeric context, and vice versa. ...@@ -13267,7 +13266,7 @@ if the value is used in a numeric context, and vice versa.
@item @item
When @strong{MySQL} encounters a value for a date or time type that is When @strong{MySQL} encounters a value for a date or time type that is
out of range or otherwise illegal for the type (see start of this out of range or otherwise illegal for the type (see the start of this
section), it converts the value to the ``zero'' value for that type. section), it converts the value to the ``zero'' value for that type.
(The exception is that out-of-range @code{TIME} values are clipped to (The exception is that out-of-range @code{TIME} values are clipped to
the appropriate endpoint of the @code{TIME} range.) The table below the appropriate endpoint of the @code{TIME} range.) The table below
...@@ -13289,13 +13288,13 @@ using the values @code{'0'} or @code{0}, which are easier to write. ...@@ -13289,13 +13288,13 @@ using the values @code{'0'} or @code{0}, which are easier to write.
@item @item
``Zero'' date or time values used through @strong{MyODBC} are converted ``Zero'' date or time values used through @strong{MyODBC} are converted
automatically to @code{NULL} in @strong{MyODBC} 2.50.12 and above, because automatically to @code{NULL} in @strong{MyODBC} Version 2.50.12 and above,
ODBC can't handle such values. because ODBC can't handle such values.
@end itemize @end itemize
@cindex Year 2000 issues @cindex Year 2000 issues
@node Y2K issues, DATETIME, Date and time types, Date and time types @node Y2K issues, DATETIME, Date and time types, Date and time types
@subsubsection Y2K issues and date types @subsubsection Y2K Issues and Date Types
@strong{MySQL} itself is Y2K-safe (@pxref{Year 2000 compliance}), @strong{MySQL} itself is Y2K-safe (@pxref{Year 2000 compliance}),
but input values presented to @strong{MySQL} may not be. Any input but input values presented to @strong{MySQL} may not be. Any input
...@@ -13303,7 +13302,7 @@ containing 2-digit year values is ambiguous, because the century is unknown. ...@@ -13303,7 +13302,7 @@ containing 2-digit year values is ambiguous, because the century is unknown.
Such values must be interpreted into 4-digit form because @strong{MySQL} stores Such values must be interpreted into 4-digit form because @strong{MySQL} stores
years internally using four digits. years internally using four digits.
For @code{DATETIME}, @code{DATE}, @code{TIMESTAMP} and @code{YEAR} types, For @code{DATETIME}, @code{DATE}, @code{TIMESTAMP}, and @code{YEAR} types,
@strong{MySQL} interprets dates with ambiguous year values using the @strong{MySQL} interprets dates with ambiguous year values using the
following rules: following rules:
...@@ -13320,22 +13319,22 @@ data mean. If the heuristics used by @strong{MySQL} don't produce the ...@@ -13320,22 +13319,22 @@ data mean. If the heuristics used by @strong{MySQL} don't produce the
correct values, you should provide unambiguous input containing 4-digit correct values, you should provide unambiguous input containing 4-digit
year values. year values.
@code{ORDER BY} will sort 2 digit @code{YEAR/DATE/DATETIME} types properly. @code{ORDER BY} will sort 2-digit @code{YEAR/DATE/DATETIME} types properly.
Note also that some functions like @code{MIN()} and @code{MAX()} will convert a Note also that some functions like @code{MIN()} and @code{MAX()} will convert a
@code{TIMESTAMP/DATE} to a number. This means that a timestamp with a 2 @code{TIMESTAMP/DATE} to a number. This means that a timestamp with a
digit year will not work properly with these functions. The fix in this 2-digit year will not work properly with these functions. The fix in this
case is to convert the @code{TIMESTAMP/DATE} to 4 digit year format or case is to convert the @code{TIMESTAMP/DATE} to 4-digit year format or
use something like @code{MIN(DATE_ADD(timestamp,INTERVAL 0 DAYS))}. use something like @code{MIN(DATE_ADD(timestamp,INTERVAL 0 DAYS))}.
@tindex DATETIME @tindex DATETIME
@tindex DATE @tindex DATE
@tindex TIMESTAMP @tindex TIMESTAMP
@node DATETIME, TIME, Y2K issues, Date and time types @node DATETIME, TIME, Y2K issues, Date and time types
@subsubsection The @code{DATETIME}, @code{DATE} and @code{TIMESTAMP} types @subsubsection The @code{DATETIME}, @code{DATE}, and @code{TIMESTAMP} Types
The @code{DATETIME}, @code{DATE} and @code{TIMESTAMP} types are related. The @code{DATETIME}, @code{DATE}, and @code{TIMESTAMP} types are related.
This section describes their characteristics, how they are similar and how This section describes their characteristics, how they are similar, and how
they differ. they differ.
The @code{DATETIME} type is used when you need values that contain both date The @code{DATETIME} type is used when you need values that contain both date
...@@ -13373,7 +13372,7 @@ You explicitly set the @code{TIMESTAMP} column to @code{NULL}. ...@@ -13373,7 +13372,7 @@ You explicitly set the @code{TIMESTAMP} column to @code{NULL}.
@end itemize @end itemize
@code{TIMESTAMP} columns other than the first may also be set to the current @code{TIMESTAMP} columns other than the first may also be set to the current
date and time. Just set the column to @code{NULL}, or to @code{NOW()}. date and time. Just set the column to @code{NULL} or to @code{NOW()}.
You can set any @code{TIMESTAMP} column to a value different than the current You can set any @code{TIMESTAMP} column to a value different than the current
date and time by setting it explicitly to the desired value. This is true date and time by setting it explicitly to the desired value. This is true
...@@ -13422,7 +13421,7 @@ specify an arbitrary display size at table creation time, but values of 0 or ...@@ -13422,7 +13421,7 @@ specify an arbitrary display size at table creation time, but values of 0 or
greater than 14 are coerced to 14. Odd-valued sizes in the range from 1 to greater than 14 are coerced to 14. Odd-valued sizes in the range from 1 to
13 are coerced to the next higher even number. 13 are coerced to the next higher even number.
You can specify @code{DATETIME}, @code{DATE} and @code{TIMESTAMP} values using You can specify @code{DATETIME}, @code{DATE}, and @code{TIMESTAMP} values using
any of a common set of formats: any of a common set of formats:
@itemize @bullet @itemize @bullet
...@@ -13431,13 +13430,13 @@ As a string in either @code{'YYYY-MM-DD HH:MM:SS'} or @code{'YY-MM-DD ...@@ -13431,13 +13430,13 @@ As a string in either @code{'YYYY-MM-DD HH:MM:SS'} or @code{'YY-MM-DD
HH:MM:SS'} format. A ``relaxed'' syntax is allowed---any punctuation HH:MM:SS'} format. A ``relaxed'' syntax is allowed---any punctuation
character may be used as the delimiter between date parts or time parts. character may be used as the delimiter between date parts or time parts.
For example, @code{'98-12-31 11:30:45'}, @code{'98.12.31 11+30+45'}, For example, @code{'98-12-31 11:30:45'}, @code{'98.12.31 11+30+45'},
@code{'98/12/31 11*30*45'} and @code{'98@@12@@31 11^30^45'} are @code{'98/12/31 11*30*45'}, and @code{'98@@12@@31 11^30^45'} are
equivalent. equivalent.
@item @item
As a string in either @code{'YYYY-MM-DD'} or @code{'YY-MM-DD'} format. As a string in either @code{'YYYY-MM-DD'} or @code{'YY-MM-DD'} format.
A ``relaxed'' syntax is allowed here, too. For example, @code{'98-12-31'}, A ``relaxed'' syntax is allowed here, too. For example, @code{'98-12-31'},
@code{'98.12.31'}, @code{'98/12/31'} and @code{'98@@12@@31'} are @code{'98.12.31'}, @code{'98/12/31'}, and @code{'98@@12@@31'} are
equivalent. equivalent.
@item @item
...@@ -13468,23 +13467,23 @@ format, provided that the number makes sense as a date. For example, ...@@ -13468,23 +13467,23 @@ format, provided that the number makes sense as a date. For example,
@item @item
As the result of a function that returns a value that is acceptable As the result of a function that returns a value that is acceptable
in a @code{DATETIME}, @code{DATE} or @code{TIMESTAMP} context, such as in a @code{DATETIME}, @code{DATE}, or @code{TIMESTAMP} context, such as
@code{NOW()} or @code{CURRENT_DATE}. @code{NOW()} or @code{CURRENT_DATE}.
@end itemize @end itemize
Illegal @code{DATETIME}, @code{DATE} or @code{TIMESTAMP} values are converted Illegal @code{DATETIME}, @code{DATE}, or @code{TIMESTAMP} values are converted
to the ``zero'' value of the appropriate type (@code{'0000-00-00 00:00:00'}, to the ``zero'' value of the appropriate type (@code{'0000-00-00 00:00:00'},
@code{'0000-00-00'} or @code{00000000000000}). @code{'0000-00-00'}, or @code{00000000000000}).
For values specified as strings that include date part delimiters, it is not For values specified as strings that include date part delimiters, it is not
necessary to specify two digits for month or day values that are less than necessary to specify two digits for month or day values that are less than
@code{10}. @code{'1979-6-9'} is the same as @code{'1979-06-09'}. Similarly, @code{10}. @code{'1979-6-9'} is the same as @code{'1979-06-09'}. Similarly,
for values specified as strings that include time part delimiters, it is not for values specified as strings that include time part delimiters, it is not
necessary to specify two digits for hour, month or second values that are necessary to specify two digits for hour, month, or second values that are
less than @code{10}. @code{'1979-10-30 1:2:3'} is the same as less than @code{10}. @code{'1979-10-30 1:2:3'} is the same as
@code{'1979-10-30 01:02:03'}. @code{'1979-10-30 01:02:03'}.
Values specified as numbers should be 6, 8, 12 or 14 digits long. If the Values specified as numbers should be 6, 8, 12, or 14 digits long. If the
number is 8 or 14 digits long, it is assumed to be in @code{YYYYMMDD} or number is 8 or 14 digits long, it is assumed to be in @code{YYYYMMDD} or
@code{YYYYMMDDHHMMSS} format and that the year is given by the first 4 @code{YYYYMMDDHHMMSS} format and that the year is given by the first 4
digits. If the number is 6 or 12 digits long, it is assumed to be in digits. If the number is 6 or 12 digits long, it is assumed to be in
...@@ -13496,7 +13495,7 @@ Values specified as non-delimited strings are interpreted using their length ...@@ -13496,7 +13495,7 @@ Values specified as non-delimited strings are interpreted using their length
as given. If the string is 8 or 14 characters long, the year is assumed to as given. If the string is 8 or 14 characters long, the year is assumed to
be given by the first 4 characters. Otherwise the year is assumed to be be given by the first 4 characters. Otherwise the year is assumed to be
given by the first 2 characters. The string is interpreted from left to given by the first 2 characters. The string is interpreted from left to
right to find year, month, day, hour, minute and second values, for as many right to find year, month, day, hour, minute, and second values, for as many
parts as are present in the string. This means you should not use strings parts as are present in the string. This means you should not use strings
that have fewer than 6 characters. For example, if you specify @code{'9903'}, that have fewer than 6 characters. For example, if you specify @code{'9903'},
thinking that will represent March, 1999, you will find that @strong{MySQL} thinking that will represent March, 1999, you will find that @strong{MySQL}
...@@ -13551,7 +13550,7 @@ object, the time part of the resulting value is deleted, because the ...@@ -13551,7 +13550,7 @@ object, the time part of the resulting value is deleted, because the
@code{DATE} type stores no time information. @code{DATE} type stores no time information.
@item @item
Remember that although @code{DATETIME}, @code{DATE} and @code{TIMESTAMP} Remember that although @code{DATETIME}, @code{DATE}, and @code{TIMESTAMP}
values all can be specified using the same set of formats, the types do not values all can be specified using the same set of formats, the types do not
all have the same range of values. For example, @code{TIMESTAMP} values all have the same range of values. For example, @code{TIMESTAMP} values
cannot be earlier than @code{1970} or later than @code{2037}. This means cannot be earlier than @code{1970} or later than @code{2037}. This means
...@@ -13587,7 +13586,7 @@ Year values in the range @code{70-99} are converted to @code{1970-1999}. ...@@ -13587,7 +13586,7 @@ Year values in the range @code{70-99} are converted to @code{1970-1999}.
@tindex TIME @tindex TIME
@node TIME, YEAR, DATETIME, Date and time types @node TIME, YEAR, DATETIME, Date and time types
@subsubsection The @code{TIME} type @subsubsection The @code{TIME} Type
@strong{MySQL} retrieves and displays @code{TIME} values in @code{'HH:MM:SS'} @strong{MySQL} retrieves and displays @code{TIME} values in @code{'HH:MM:SS'}
format (or @code{'HHH:MM:SS'} format for large hours values). @code{TIME} format (or @code{'HHH:MM:SS'} format for large hours values). @code{TIME}
...@@ -13627,15 +13626,15 @@ in a @code{TIME} context, such as @code{CURRENT_TIME}. ...@@ -13627,15 +13626,15 @@ in a @code{TIME} context, such as @code{CURRENT_TIME}.
@end itemize @end itemize
For @code{TIME} values specified as strings that include a time part For @code{TIME} values specified as strings that include a time part
delimiter, it is not necessary to specify two digits for hours, minutes or delimiter, it is not necessary to specify two digits for hours, minutes, or
seconds values that are less than @code{10}. @code{'8:3:2'} is the same as seconds values that are less than @code{10}. @code{'8:3:2'} is the same as
@code{'08:03:02'}. @code{'08:03:02'}.
Be careful about assigning ``short'' @code{TIME} values to a @code{TIME} Be careful about assigning ``short'' @code{TIME} values to a @code{TIME}
column. @strong{MySQL} interprets values using the assumption that the column. @strong{MySQL} interprets values using the assumption that the
rightmost digits represent seconds. (@strong{MySQL} interprets @code{TIME} rightmost digits represent seconds. (@strong{MySQL} interprets @code{TIME}
values as elapsed time, rather than as time of day.) For example, you might values as elapsed time rather than as time of day.) For example, you might
think of @code{'11:12'}, @code{'1112'} and @code{1112} as meaning think of @code{'11:12'}, @code{'1112'}, and @code{1112} as meaning
@code{'11:12:00'} (12 minutes after 11 o'clock), but @strong{MySQL} @code{'11:12:00'} (12 minutes after 11 o'clock), but @strong{MySQL}
interprets them as @code{'00:11:12'} (11 minutes, 12 seconds). Similarly, interprets them as @code{'00:11:12'} (11 minutes, 12 seconds). Similarly,
@code{'12'} and @code{12} are interpreted as @code{'00:00:12'}. @code{'12'} and @code{12} are interpreted as @code{'00:00:12'}.
...@@ -13653,7 +13652,7 @@ original value was specified as @code{'00:00:00'} or whether it was illegal. ...@@ -13653,7 +13652,7 @@ original value was specified as @code{'00:00:00'} or whether it was illegal.
@tindex YEAR @tindex YEAR
@node YEAR, , TIME, Date and time types @node YEAR, , TIME, Date and time types
@subsubsection The @code{YEAR} type @subsubsection The @code{YEAR} Type
The @code{YEAR} type is a 1-byte type used for representing years. The @code{YEAR} type is a 1-byte type used for representing years.
...@@ -13693,10 +13692,10 @@ in a @code{YEAR} context, such as @code{NOW()}. ...@@ -13693,10 +13692,10 @@ in a @code{YEAR} context, such as @code{NOW()}.
Illegal @code{YEAR} values are converted to @code{0000}. Illegal @code{YEAR} values are converted to @code{0000}.
@node String types, Choosing types, Date and time types, Column types @node String types, Choosing types, Date and time types, Column types
@subsection String types @subsection String Types
The string types are @code{CHAR}, @code{VARCHAR}, @code{BLOB}, @code{TEXT}, The string types are @code{CHAR}, @code{VARCHAR}, @code{BLOB}, @code{TEXT},
@code{ENUM} and @code{SET}. @code{ENUM}, and @code{SET}.
@tindex CHAR @tindex CHAR
@tindex VARCHAR @tindex VARCHAR
...@@ -13708,14 +13707,14 @@ The string types are @code{CHAR}, @code{VARCHAR}, @code{BLOB}, @code{TEXT}, ...@@ -13708,14 +13707,14 @@ The string types are @code{CHAR}, @code{VARCHAR}, @code{BLOB}, @code{TEXT},
@end menu @end menu
@node CHAR, BLOB, String types, String types @node CHAR, BLOB, String types, String types
@subsubsection The @code{CHAR} and @code{VARCHAR} types @subsubsection The @code{CHAR} and @code{VARCHAR} Types
The @code{CHAR} and @code{VARCHAR} types are similar, but differ in the The @code{CHAR} and @code{VARCHAR} types are similar, but differ in the
way they are stored and retrieved. way they are stored and retrieved.
The length of a @code{CHAR} column is fixed to the length that you declare The length of a @code{CHAR} column is fixed to the length that you declare
when you create the table. The length can be any value between 1 and 255. when you create the table. The length can be any value between 1 and 255.
(As of @strong{MySQL} 3.23, the length of @code{CHAR} may be 0 to 255.) (As of @strong{MySQL} Version 3.23, the length of @code{CHAR} may be 0 to 255.)
When @code{CHAR} values are stored, they are right-padded with spaces to the When @code{CHAR} values are stored, they are right-padded with spaces to the
specified length. When @code{CHAR} values are retrieved, trailing spaces are specified length. When @code{CHAR} values are retrieved, trailing spaces are
removed. removed.
...@@ -13756,7 +13755,7 @@ when the table was created. The @code{BINARY} attribute means that column ...@@ -13756,7 +13755,7 @@ when the table was created. The @code{BINARY} attribute means that column
values are sorted and compared in case-sensitive fashion according to the values are sorted and compared in case-sensitive fashion according to the
ASCII order of the machine where the @strong{MySQL} server is running. ASCII order of the machine where the @strong{MySQL} server is running.
The @code{BINARY} attribute is ``sticky''. This means that if a column marked The @code{BINARY} attribute is sticky. This means that if a column marked
@code{BINARY} is used in an expression, the whole expression is compared as a @code{BINARY} is used in an expression, the whole expression is compared as a
@code{BINARY} value. @code{BINARY} value.
...@@ -13767,15 +13766,15 @@ column at table creation time. ...@@ -13767,15 +13766,15 @@ column at table creation time.
@tindex BLOB @tindex BLOB
@tindex TEXT @tindex TEXT
@node BLOB, ENUM, CHAR, String types @node BLOB, ENUM, CHAR, String types
@subsubsection The @code{BLOB} and @code{TEXT} types @subsubsection The @code{BLOB} and @code{TEXT} Types
A @code{BLOB} is a binary large object that can hold a variable amount of A @code{BLOB} is a binary large object that can hold a variable amount of
data. The four @code{BLOB} types @code{TINYBLOB}, @code{BLOB}, data. The four @code{BLOB} types @code{TINYBLOB}, @code{BLOB},
@code{MEDIUMBLOB} and @code{LONGBLOB} differ only in the maximum length of @code{MEDIUMBLOB}, and @code{LONGBLOB} differ only in the maximum length of
the values they can hold. the values they can hold.
@xref{Storage requirements}. @xref{Storage requirements}.
The four @code{TEXT} types @code{TINYTEXT}, @code{TEXT}, @code{MEDIUMTEXT} The four @code{TEXT} types @code{TINYTEXT}, @code{TEXT}, @code{MEDIUMTEXT},
and @code{LONGTEXT} correspond to the four @code{BLOB} types and have the and @code{LONGTEXT} correspond to the four @code{BLOB} types and have the
same maximum lengths and storage requirements. The only difference between same maximum lengths and storage requirements. The only difference between
@code{BLOB} and @code{TEXT} types is that sorting and comparison is performed @code{BLOB} and @code{TEXT} types is that sorting and comparison is performed
...@@ -13793,7 +13792,7 @@ column that can be as big as you like. Similarly, you can regard a ...@@ -13793,7 +13792,7 @@ column that can be as big as you like. Similarly, you can regard a
@itemize @bullet @itemize @bullet
@item @item
You can have indexes on @code{BLOB} and @code{TEXT} columns with You can have indexes on @code{BLOB} and @code{TEXT} columns with
@strong{MySQL} versions 3.23.2 and newer. Older versions of @strong{MySQL} Version 3.23.2 and newer. Older versions of
@strong{MySQL} did not support this. @strong{MySQL} did not support this.
@item @item
...@@ -13847,12 +13846,12 @@ do so on both the server and client ends. @xref{Server parameters}. ...@@ -13847,12 +13846,12 @@ do so on both the server and client ends. @xref{Server parameters}.
@end itemize @end itemize
Note that each @code{BLOB} or @code{TEXT} value is represented internally by Note that each @code{BLOB} or @code{TEXT} value is represented internally by
a separately-allocated object. This is in contrast to all other column types, a separately allocated object. This is in contrast to all other column types,
for which storage is allocated once per column when the table is opened. for which storage is allocated once per column when the table is opened.
@tindex ENUM @tindex ENUM
@node ENUM, SET, BLOB, String types @node ENUM, SET, BLOB, String types
@subsubsection The @code{ENUM} type @subsubsection The @code{ENUM} Type
An @code{ENUM} is a string object whose value normally is chosen from a list An @code{ENUM} is a string object whose value normally is chosen from a list
of allowed values that are enumerated explicitly in the column specification of allowed values that are enumerated explicitly in the column specification
...@@ -13914,7 +13913,7 @@ values that were used to specify the allowable values at table creation time. ...@@ -13914,7 +13913,7 @@ values that were used to specify the allowable values at table creation time.
If you retrieve an @code{ENUM} in a numeric context, the column value's index If you retrieve an @code{ENUM} in a numeric context, the column value's index
is returned. If you store a number into an @code{ENUM}, the number is is returned. If you store a number into an @code{ENUM}, the number is
treated as an index, and the the value stored is the enumeration member with treated as an index, and the value stored is the enumeration member with
that index. (However, this will not work with @code{LOAD DATA}, which treats that index. (However, this will not work with @code{LOAD DATA}, which treats
all input as strings.) all input as strings.)
...@@ -13932,7 +13931,7 @@ the @code{ENUM} definition in the second column. ...@@ -13932,7 +13931,7 @@ the @code{ENUM} definition in the second column.
@tindex SET @tindex SET
@node SET, , ENUM, String types @node SET, , ENUM, String types
@subsubsection The @code{SET} type @subsubsection The @code{SET} Type
A @code{SET} is a string object that can have zero or more values, each of A @code{SET} is a string object that can have zero or more values, each of
which must be chosen from a list of allowed values specified when the table which must be chosen from a list of allowed values specified when the table
...@@ -13980,7 +13979,7 @@ does not matter how many times a given element is listed in the value. ...@@ -13980,7 +13979,7 @@ does not matter how many times a given element is listed in the value.
When the value is retrieved later, each element in the value will appear When the value is retrieved later, each element in the value will appear
once, with elements listed according to the order in which they were once, with elements listed according to the order in which they were
specified at table creation time. For example, if a column is specified as specified at table creation time. For example, if a column is specified as
@code{SET("a","b","c","d")}, then @code{"a,d"}, @code{"d,a"} and @code{SET("a","b","c","d")}, then @code{"a,d"}, @code{"d,a"}, and
@code{"d,a,a,d,d"} will all appear as @code{"a,d"} when retrieved. @code{"d,a,a,d,d"} will all appear as @code{"a,d"} when retrieved.
@code{SET} values are sorted numerically. @code{NULL} values sort before @code{SET} values are sorted numerically. @code{NULL} values sort before
...@@ -14011,7 +14010,7 @@ the @code{SET} definition in the second column. ...@@ -14011,7 +14010,7 @@ the @code{SET} definition in the second column.
@cindex Types, choosing @cindex Types, choosing
@cindex Choosing types @cindex Choosing types
@node Choosing types, Indexes, String types, Column types @node Choosing types, Indexes, String types, Column types
@subsection Choosing the right type for a column @subsection Choosing the Right Type for a Column
For the most efficient use of storage, try to use the most precise type in For the most efficient use of storage, try to use the most precise type in
all cases. For example, if an integer column will be used for values in the all cases. For example, if an integer column will be used for values in the
...@@ -14030,7 +14029,7 @@ and convert results back to floating-point values only when necessary. ...@@ -14030,7 +14029,7 @@ and convert results back to floating-point values only when necessary.
@cindex Indexes @cindex Indexes
@cindex Keys @cindex Keys
@node Indexes, Multiple-column indexes, Choosing types, Column types @node Indexes, Multiple-column indexes, Choosing types, Column types
@subsection Column indexes @subsection Column Indexes
All @strong{MySQL} column types can be indexed. Use of indexes on the All @strong{MySQL} column types can be indexed. Use of indexes on the
relevant columns is the best way to improve the performance of @code{SELECT} relevant columns is the best way to improve the performance of @code{SELECT}
...@@ -14058,17 +14057,17 @@ mysql> CREATE TABLE test ( ...@@ -14058,17 +14057,17 @@ mysql> CREATE TABLE test (
@end example @end example
For @code{BLOB} and @code{TEXT} columns, you must index a prefix of the For @code{BLOB} and @code{TEXT} columns, you must index a prefix of the
column, you cannot index the entire thing. column. You cannot index the entire column.
In @strong{MySQL} 3.23.23 or later, you can also create special In @strong{MySQL} Version 3.23.23 or later, you can also create special
@strong{FULLTEXT} indexes. They are used for full-text search. Only the @strong{FULLTEXT} indexes. They are used for full-text search. Only the
@code{MyISAM} table type supports @code{FULLTEXT} indexes. They can be created @code{MyISAM} table type supports @code{FULLTEXT} indexes. They can be
only from @code{VARCHAR} and @code{TEXT} columns. created only from @code{VARCHAR} and @code{TEXT} columns.
Indexing always happens over the entire column, partial indexing is not Indexing always happens over the entire column and partial indexing is not
supported. See @ref{MySQL full-text search} for details of operation. supported. See @ref{MySQL full-text search} for details.
@node Multiple-column indexes, Other-vendor column types, Indexes, Column types @node Multiple-column indexes, Other-vendor column types, Indexes, Column types
@subsection Multiple-column indexes @subsection Multiple-column Indexes
@strong{MySQL} can create indexes on multiple columns. An index may @strong{MySQL} can create indexes on multiple columns. An index may
consist of up to 15 columns. (On @code{CHAR} and @code{VARCHAR} columns you consist of up to 15 columns. (On @code{CHAR} and @code{VARCHAR} columns you
...@@ -14126,7 +14125,7 @@ indexes}. ...@@ -14126,7 +14125,7 @@ indexes}.
@cindex Type portability @cindex Type portability
@node Other-vendor column types, , Multiple-column indexes, Column types @node Other-vendor column types, , Multiple-column indexes, Column types
@subsection Using column types from other database engines @subsection Using Column Types from Other Database Engines
To make it easier to use code written for SQL implementations from other To make it easier to use code written for SQL implementations from other
vendors, @strong{MySQL} maps column types as shown in the table below. These vendors, @strong{MySQL} maps column types as shown in the table below. These
...@@ -14157,7 +14156,7 @@ statement, @strong{MySQL} reports the table structure using the equivalent ...@@ -14157,7 +14156,7 @@ statement, @strong{MySQL} reports the table structure using the equivalent
@cindex Functions for @code{SELECT} and @code{WHERE} clauses @cindex Functions for @code{SELECT} and @code{WHERE} clauses
@node Functions, CREATE DATABASE, Column types, Reference @node Functions, CREATE DATABASE, Column types, Reference
@section Functions for use in @code{SELECT} and @code{WHERE} clauses @section Functions for Use in @code{SELECT} and @code{WHERE} Clauses
A @code{select_expression} or @code{where_definition} in a SQL statement A @code{select_expression} or @code{where_definition} in a SQL statement
can consist of any expression using the functions described below. can consist of any expression using the functions described below.
...@@ -14166,7 +14165,7 @@ An expression that contains @code{NULL} always produces a @code{NULL} value ...@@ -14166,7 +14165,7 @@ An expression that contains @code{NULL} always produces a @code{NULL} value
unless otherwise indicated in the documentation for the operators and unless otherwise indicated in the documentation for the operators and
functions involved in the expression. functions involved in the expression.
@strong{Note:} There must be no whitespace between a function name and the @strong{NOTE:} There must be no whitespace between a function name and the
parenthesis following it. This helps the @strong{MySQL} parser distinguish parenthesis following it. This helps the @strong{MySQL} parser distinguish
between function calls and references to tables or columns that happen to between function calls and references to tables or columns that happen to
have the same name as a function. Spaces around arguments are permitted, have the same name as a function. Spaces around arguments are permitted,
...@@ -14187,7 +14186,7 @@ mysql> select MOD(29,9); ...@@ -14187,7 +14186,7 @@ mysql> select MOD(29,9);
+-----------+ +-----------+
@end example @end example
Is displayed like this: is displayed like this:
@example @example
mysql> select MOD(29,9); mysql> select MOD(29,9);
...@@ -14211,14 +14210,14 @@ mysql> select MOD(29,9); ...@@ -14211,14 +14210,14 @@ mysql> select MOD(29,9);
@end menu @end menu
@node Grouping functions, Arithmetic functions, Functions, Functions @node Grouping functions, Arithmetic functions, Functions, Functions
@subsection Grouping functions @subsection Grouping Functions
@cindex Grouping of expressions @cindex Grouping of expressions
@table @code @table @code
@findex () (parentheses) @findex () (parentheses)
@findex parentheses ( and ) @findex parentheses ( and )
@item ( ... ) @item ( ... )
Parentheses. Use these to force the order of evaluation in an expression. Parentheses. Use these to force the order of evaluation in an expression:
@example @example
mysql> select 1+2*3; mysql> select 1+2*3;
-> 7 -> 7
...@@ -14228,10 +14227,10 @@ mysql> select (1+2)*3; ...@@ -14228,10 +14227,10 @@ mysql> select (1+2)*3;
@end table @end table
@node Arithmetic functions, Bit functions, Grouping functions, Functions @node Arithmetic functions, Bit functions, Grouping functions, Functions
@subsection Normal arithmetic operations @subsection Normal Arithmetic Operations
The usual arithmetic operators are available. Note that in the case of The usual arithmetic operators are available. Note that in the case of
@code{-}, @code{+} and @code{*}, the result is calculated with @code{BIGINT} @samp{-}, @samp{+}, and @samp{*}, the result is calculated with @code{BIGINT}
(64-bit) precision if both arguments are integers! (64-bit) precision if both arguments are integers!
@cindex Arithmetic expressions @cindex Arithmetic expressions
...@@ -14239,7 +14238,7 @@ The usual arithmetic operators are available. Note that in the case of ...@@ -14239,7 +14238,7 @@ The usual arithmetic operators are available. Note that in the case of
@findex + (addition) @findex + (addition)
@findex addition (+) @findex addition (+)
@item + @item +
Addition Addition:
@example @example
mysql> select 3+5; mysql> select 3+5;
-> 8 -> 8
...@@ -14248,7 +14247,7 @@ mysql> select 3+5; ...@@ -14248,7 +14247,7 @@ mysql> select 3+5;
@findex - (subtraction) @findex - (subtraction)
@findex subtraction (-) @findex subtraction (-)
@item - @item -
Subtraction Subtraction:
@example @example
mysql> select 3-5; mysql> select 3-5;
-> -2 -> -2
...@@ -14257,7 +14256,7 @@ mysql> select 3-5; ...@@ -14257,7 +14256,7 @@ mysql> select 3-5;
@findex * (multiplication) @findex * (multiplication)
@findex multiplication (*) @findex multiplication (*)
@item * @item *
Multiplication Multiplication:
@example @example
mysql> select 3*5; mysql> select 3*5;
-> 15 -> 15
...@@ -14273,7 +14272,7 @@ multiplication exceeds the 64-bit range of @code{BIGINT} calculations. ...@@ -14273,7 +14272,7 @@ multiplication exceeds the 64-bit range of @code{BIGINT} calculations.
@findex / (division) @findex / (division)
@findex division (/) @findex division (/)
@item / @item /
Division Division:
@example @example
mysql> select 3/5; mysql> select 3/5;
-> 0.60 -> 0.60
...@@ -14295,7 +14294,7 @@ in a context where its result is converted to an integer! ...@@ -14295,7 +14294,7 @@ in a context where its result is converted to an integer!
@findex Functions, arithmetic @findex Functions, arithmetic
@findex Functions, bit @findex Functions, bit
@node Bit functions, Logical functions, Arithmetic functions, Functions @node Bit functions, Logical functions, Arithmetic functions, Functions
@subsection Bit functions @subsection Bit Functions
@strong{MySQL} uses @code{BIGINT} (64-bit) arithmetic for bit operations, so @strong{MySQL} uses @code{BIGINT} (64-bit) arithmetic for bit operations, so
these operators have a maximum range of 64 bits. these operators have a maximum range of 64 bits.
...@@ -14304,7 +14303,7 @@ these operators have a maximum range of 64 bits. ...@@ -14304,7 +14303,7 @@ these operators have a maximum range of 64 bits.
@findex | (bitwise OR) @findex | (bitwise OR)
@findex OR, bitwise @findex OR, bitwise
@item | @item |
Bitwise OR Bitwise OR:
@example @example
mysql> select 29 | 15; mysql> select 29 | 15;
-> 31 -> 31
...@@ -14313,7 +14312,7 @@ mysql> select 29 | 15; ...@@ -14313,7 +14312,7 @@ mysql> select 29 | 15;
@findex & (bitwise AND) @findex & (bitwise AND)
@findex AND, bitwise @findex AND, bitwise
@item & @item &
Bitwise AND Bitwise AND:
@example @example
mysql> select 29 & 15; mysql> select 29 & 15;
-> 13 -> 13
...@@ -14321,7 +14320,7 @@ mysql> select 29 & 15; ...@@ -14321,7 +14320,7 @@ mysql> select 29 & 15;
@findex << (left shift) @findex << (left shift)
@item << @item <<
Shifts a longlong (@code{BIGINT}) number to the left. Shifts a longlong (@code{BIGINT}) number to the left:
@example @example
mysql> select 1 << 2 mysql> select 1 << 2
-> 4 -> 4
...@@ -14329,7 +14328,7 @@ mysql> select 1 << 2 ...@@ -14329,7 +14328,7 @@ mysql> select 1 << 2
@findex >> (right shift) @findex >> (right shift)
@item >> @item >>
Shifts a longlong (@code{BIGINT}) number to the right. Shifts a longlong (@code{BIGINT}) number to the right:
@example @example
mysql> select 4 >> 2 mysql> select 4 >> 2
-> 1 -> 1
...@@ -14337,7 +14336,7 @@ mysql> select 4 >> 2 ...@@ -14337,7 +14336,7 @@ mysql> select 4 >> 2
@findex ~ @findex ~
@item ~ @item ~
Invert all bits. Invert all bits:
@example @example
mysql> select 5 & ~1 mysql> select 5 & ~1
-> 4 -> 4
...@@ -14345,7 +14344,7 @@ mysql> select 5 & ~1 ...@@ -14345,7 +14344,7 @@ mysql> select 5 & ~1
@findex BIT_COUNT() @findex BIT_COUNT()
@item BIT_COUNT(N) @item BIT_COUNT(N)
Returns the number of bits that are set in the argument @code{N}. Returns the number of bits that are set in the argument @code{N}:
@example @example
mysql> select BIT_COUNT(29); mysql> select BIT_COUNT(29);
-> 4 -> 4
...@@ -14355,9 +14354,9 @@ mysql> select BIT_COUNT(29); ...@@ -14355,9 +14354,9 @@ mysql> select BIT_COUNT(29);
@findex Logical functions @findex Logical functions
@findex Functions, logical @findex Functions, logical
@node Logical functions, Comparison functions, Bit functions, Functions @node Logical functions, Comparison functions, Bit functions, Functions
@subsection Logical operations @subsection Logical Operations
All logical functions return @code{1} (TRUE) or @code{0} (FALSE). All logical functions return @code{1} (TRUE) or @code{0} (FALSE):
@table @code @table @code
@findex NOT, logical @findex NOT, logical
...@@ -14366,7 +14365,7 @@ All logical functions return @code{1} (TRUE) or @code{0} (FALSE). ...@@ -14366,7 +14365,7 @@ All logical functions return @code{1} (TRUE) or @code{0} (FALSE).
@itemx ! @itemx !
Logical NOT. Returns @code{1} if the argument is @code{0}, otherwise returns Logical NOT. Returns @code{1} if the argument is @code{0}, otherwise returns
@code{0}. @code{0}.
Exception: @code{NOT NULL} returns @code{NULL}. Exception: @code{NOT NULL} returns @code{NULL}:
@example @example
mysql> select NOT 1; mysql> select NOT 1;
-> 0 -> 0
...@@ -14385,7 +14384,7 @@ the same way as @code{(!1)+1}. ...@@ -14385,7 +14384,7 @@ the same way as @code{(!1)+1}.
@item OR @item OR
@itemx || @itemx ||
Logical OR. Returns @code{1} if either argument is not @code{0} and not Logical OR. Returns @code{1} if either argument is not @code{0} and not
@code{NULL}. @code{NULL}:
@example @example
mysql> select 1 || 0; mysql> select 1 || 0;
-> 1 -> 1
...@@ -14401,7 +14400,7 @@ mysql> select 1 || NULL; ...@@ -14401,7 +14400,7 @@ mysql> select 1 || NULL;
@item AND @item AND
@itemx && @itemx &&
Logical AND. Returns @code{0} if either argument is @code{0} or @code{NULL}, Logical AND. Returns @code{0} if either argument is @code{0} or @code{NULL},
otherwise returns @code{1}. otherwise returns @code{1}:
@example @example
mysql> select 1 && NULL; mysql> select 1 && NULL;
-> 0 -> 0
...@@ -14414,9 +14413,9 @@ mysql> select 1 && 0; ...@@ -14414,9 +14413,9 @@ mysql> select 1 && 0;
@cindex Type conversions @cindex Type conversions
@findex Comparison operators @findex Comparison operators
@node Comparison functions, String comparison functions, Logical functions, Functions @node Comparison functions, String comparison functions, Logical functions, Functions
@subsection Comparison operators @subsection Comparison Operators
Comparison operations result in a value of @code{1} (TRUE), @code{0} (FALSE) Comparison operations result in a value of @code{1} (TRUE), @code{0} (FALSE),
or @code{NULL}. These functions work for both numbers and strings. Strings or @code{NULL}. These functions work for both numbers and strings. Strings
are automatically converted to numbers and numbers to strings as needed (as are automatically converted to numbers and numbers to strings as needed (as
in Perl). in Perl).
...@@ -14474,7 +14473,7 @@ mysql> SELECT 0 = 'x6'; ...@@ -14474,7 +14473,7 @@ mysql> SELECT 0 = 'x6';
@findex = (equal) @findex = (equal)
@findex equal (=) @findex equal (=)
@item = @item =
Equal Equal:
@example @example
mysql> select 1 = 0; mysql> select 1 = 0;
-> 0 -> 0
...@@ -14494,7 +14493,7 @@ mysql> select '.01' = 0.01; ...@@ -14494,7 +14493,7 @@ mysql> select '.01' = 0.01;
@findex not equal (!=) @findex not equal (!=)
@item <> @item <>
@itemx != @itemx !=
Not equal Not equal:
@example @example
mysql> select '.01' <> '0.01'; mysql> select '.01' <> '0.01';
-> 1 -> 1
...@@ -14507,7 +14506,7 @@ mysql> select 'zapp' <> 'zappp'; ...@@ -14507,7 +14506,7 @@ mysql> select 'zapp' <> 'zappp';
@findex <= (less than or equal) @findex <= (less than or equal)
@findex less than or equal (<=) @findex less than or equal (<=)
@item <= @item <=
Less than or equal Less than or equal:
@example @example
mysql> select 0.1 <= 2; mysql> select 0.1 <= 2;
-> 1 -> 1
...@@ -14516,7 +14515,7 @@ mysql> select 0.1 <= 2; ...@@ -14516,7 +14515,7 @@ mysql> select 0.1 <= 2;
@findex < (less than) @findex < (less than)
@findex less than (<) @findex less than (<)
@item < @item <
Less than Less than:
@example @example
mysql> select 2 <= 2; mysql> select 2 <= 2;
-> 1 -> 1
...@@ -14525,7 +14524,7 @@ mysql> select 2 <= 2; ...@@ -14525,7 +14524,7 @@ mysql> select 2 <= 2;
@findex >= (greater than or equal) @findex >= (greater than or equal)
@findex greater than or equal (>=) @findex greater than or equal (>=)
@item >= @item >=
Greater than or equal Greater than or equal:
@example @example
mysql> select 2 >= 2; mysql> select 2 >= 2;
-> 1 -> 1
...@@ -14534,7 +14533,7 @@ mysql> select 2 >= 2; ...@@ -14534,7 +14533,7 @@ mysql> select 2 >= 2;
@findex > (greater than) @findex > (greater than)
@findex greater than (>) @findex greater than (>)
@item > @item >
Greater than Greater than:
@example @example
mysql> select 2 > 2; mysql> select 2 > 2;
-> 0 -> 0
...@@ -14542,7 +14541,7 @@ mysql> select 2 > 2; ...@@ -14542,7 +14541,7 @@ mysql> select 2 > 2;
@findex <=> (Equal to) @findex <=> (Equal to)
@item <=> @item <=>
Null safe equal Null safe equal:
@example @example
mysql> select 1 <=> 1, NULL <=> NULL, 1 <=> NULL; mysql> select 1 <=> 1, NULL <=> NULL, 1 <=> NULL;
-> 1 1 0 -> 1 1 0
...@@ -14552,7 +14551,7 @@ mysql> select 1 <=> 1, NULL <=> NULL, 1 <=> NULL; ...@@ -14552,7 +14551,7 @@ mysql> select 1 <=> 1, NULL <=> NULL, 1 <=> NULL;
@findex IS NOT NULL @findex IS NOT NULL
@item IS NULL @item IS NULL
@itemx IS NOT NULL @itemx IS NOT NULL
Test whether or not a value is or is not @code{NULL} Test whether or not a value is or is not @code{NULL}:
@example @example
mysql> select 1 IS NULL, 0 IS NULL, NULL IS NULL: mysql> select 1 IS NULL, 0 IS NULL, NULL IS NULL:
-> 0 0 1 -> 0 0 1
...@@ -14571,9 +14570,9 @@ comparison is performed as follows: ...@@ -14571,9 +14570,9 @@ comparison is performed as follows:
@itemize @bullet @itemize @bullet
@item @item
If @code{expr} is a @code{TIMESTAMP}, @code{DATE} or @code{DATETIME} If @code{expr} is a @code{TIMESTAMP}, @code{DATE}, or @code{DATETIME}
column, min and max are formatted to the same format if they column, @code{MIN()} and @code{MAX()} are formatted to the same format if
are constants. they are constants.
@item @item
If @code{expr} is a case-insensitive string expression, a case-insensitive If @code{expr} is a case-insensitive string expression, a case-insensitive
string comparison is done. string comparison is done.
...@@ -14605,7 +14604,7 @@ evaluated according to the type of @code{expr} and sorted. The search for the ...@@ -14605,7 +14604,7 @@ evaluated according to the type of @code{expr} and sorted. The search for the
item is then done using a binary search. This means @code{IN} is very quick item is then done using a binary search. This means @code{IN} is very quick
if the @code{IN} value list consists entirely of constants. If @code{expr} if the @code{IN} value list consists entirely of constants. If @code{expr}
is a case-sensitive string expression, the string comparison is performed in is a case-sensitive string expression, the string comparison is performed in
case-sensitive fashion. case-sensitive fashion:
@example @example
mysql> select 2 IN (0,3,5,'wefwf'); mysql> select 2 IN (0,3,5,'wefwf');
...@@ -14621,7 +14620,7 @@ Same as @code{NOT (expr IN (value,...))}. ...@@ -14621,7 +14620,7 @@ Same as @code{NOT (expr IN (value,...))}.
@findex ISNULL() @findex ISNULL()
@item ISNULL(expr) @item ISNULL(expr)
If @code{expr} is @code{NULL}, @code{ISNULL()} returns @code{1}, otherwise If @code{expr} is @code{NULL}, @code{ISNULL()} returns @code{1}, otherwise
it returns @code{0}. it returns @code{0}:
@example @example
mysql> select ISNULL(1+1); mysql> select ISNULL(1+1);
-> 0 -> 0
...@@ -14634,7 +14633,7 @@ false! ...@@ -14634,7 +14633,7 @@ false!
@findex COALESCE() @findex COALESCE()
@item COALESCE(list) @item COALESCE(list)
Returns first non-@code{NULL} element in list. Returns first non-@code{NULL} element in list:
@example @example
mysql> select COALESCE(NULL,1); mysql> select COALESCE(NULL,1);
...@@ -14648,7 +14647,7 @@ mysql> select COALESCE(NULL,NULL,NULL); ...@@ -14648,7 +14647,7 @@ mysql> select COALESCE(NULL,NULL,NULL);
Returns @code{0} if @code{N} < @code{N1}, @code{1} if @code{N} < @code{N2} Returns @code{0} if @code{N} < @code{N1}, @code{1} if @code{N} < @code{N2}
and so on. All arguments are treated as integers. It is required that and so on. All arguments are treated as integers. It is required that
@code{N1} < @code{N2} < @code{N3} < @code{...} < @code{Nn} for this function @code{N1} < @code{N2} < @code{N3} < @code{...} < @code{Nn} for this function
to work correctly. This is because a binary search is used (very fast). to work correctly. This is because a binary search is used (very fast):
@example @example
mysql> select INTERVAL(23, 1, 15, 17, 30, 44, 200); mysql> select INTERVAL(23, 1, 15, 17, 30, 44, 200);
...@@ -14663,7 +14662,7 @@ mysql> select INTERVAL(22, 23, 30, 44, 200); ...@@ -14663,7 +14662,7 @@ mysql> select INTERVAL(22, 23, 30, 44, 200);
@findex String comparison functions @findex String comparison functions
@findex Functions, string comparison @findex Functions, string comparison
@node String comparison functions, Casts, Comparison functions, Functions @node String comparison functions, Casts, Comparison functions, Functions
@subsection String comparison functions @subsection String Comparison Functions
@cindex Case sensitivity, in string comparisons @cindex Case sensitivity, in string comparisons
@cindex String comparisons, case sensitivity @cindex String comparisons, case sensitivity
...@@ -14675,7 +14674,7 @@ comparison is performed in case-sensitive fashion. ...@@ -14675,7 +14674,7 @@ comparison is performed in case-sensitive fashion.
@item expr LIKE pat [ESCAPE 'escape-char'] @item expr LIKE pat [ESCAPE 'escape-char']
Pattern matching using Pattern matching using
SQL simple regular expression comparison. Returns @code{1} (TRUE) or @code{0} SQL simple regular expression comparison. Returns @code{1} (TRUE) or @code{0}
(FALSE). With @code{LIKE} you can use the following two wildcard characters (FALSE). With @code{LIKE} you can use the following two wild card characters
in the pattern: in the pattern:
@multitable @columnfractions .1 .9 @multitable @columnfractions .1 .9
...@@ -14690,7 +14689,7 @@ mysql> select 'David!' LIKE '%D%v%'; ...@@ -14690,7 +14689,7 @@ mysql> select 'David!' LIKE '%D%v%';
-> 1 -> 1
@end example @end example
To test for literal instances of a wildcard character, precede the character To test for literal instances of a wild card character, precede the character
with the escape character. If you don't specify the @code{ESCAPE} character, with the escape character. If you don't specify the @code{ESCAPE} character,
@samp{\} is assumed: @samp{\} is assumed:
...@@ -14721,11 +14720,11 @@ mysql> select 10 LIKE '1%'; ...@@ -14721,11 +14720,11 @@ mysql> select 10 LIKE '1%';
-> 1 -> 1
@end example @end example
Note: Because @strong{MySQL} uses the C escape syntax in strings (e.g., Note: Because @strong{MySQL} uses the C escape syntax in strings (for example,
@samp{\n}), you must double any @samp{\} that you use in your @code{LIKE} @samp{\n}), you must double any @samp{\} that you use in your @code{LIKE}
strings. For example, to search for @samp{\n}, specify it as @samp{\\n}. To strings. For example, to search for @samp{\n}, specify it as @samp{\\n}. To
search for @samp{\}, specify it as @samp{\\\\} (the backslashes are stripped search for @samp{\}, specify it as @samp{\\\\} (the backslashes are stripped
once by the parser, and another time when the pattern match is done, leaving once by the parser and another time when the pattern match is done, leaving
a single backslash to be matched). a single backslash to be matched).
@findex NOT LIKE @findex NOT LIKE
...@@ -14743,9 +14742,9 @@ Performs a pattern match of a string expression @code{expr} against a pattern ...@@ -14743,9 +14742,9 @@ Performs a pattern match of a string expression @code{expr} against a pattern
@xref{Regexp}. Returns @code{1} if @code{expr} matches @code{pat}, otherwise @xref{Regexp}. Returns @code{1} if @code{expr} matches @code{pat}, otherwise
returns @code{0}. @code{RLIKE} is a synonym for @code{REGEXP}, provided for returns @code{0}. @code{RLIKE} is a synonym for @code{REGEXP}, provided for
@code{mSQL} compatibility. Note: Because @strong{MySQL} uses the C escape @code{mSQL} compatibility. Note: Because @strong{MySQL} uses the C escape
syntax in strings (e.g., @samp{\n}), you must double any @samp{\} that you syntax in strings (for example, @samp{\n}), you must double any @samp{\} that
use in your @code{REGEXP} strings. As of @strong{MySQL} 3.23.4, you use in your @code{REGEXP} strings. As of @strong{MySQL} Version 3.23.4,
@code{REGEXP} is case insensitive for normal (not binary) strings. @code{REGEXP} is case insensitive for normal (not binary) strings:
@example @example
mysql> select 'Monty!' REGEXP 'm%y%%'; mysql> select 'Monty!' REGEXP 'm%y%%';
...@@ -14772,7 +14771,7 @@ Same as @code{NOT (expr REGEXP pat)}. ...@@ -14772,7 +14771,7 @@ Same as @code{NOT (expr REGEXP pat)}.
@code{STRCMP()} @code{STRCMP()}
returns @code{0} if the strings are the same, @code{-1} if the first returns @code{0} if the strings are the same, @code{-1} if the first
argument is smaller than the second according to the current sort order, argument is smaller than the second according to the current sort order,
and @code{1} otherwise. and @code{1} otherwise:
@example @example
mysql> select STRCMP('text', 'text2'); mysql> select STRCMP('text', 'text2');
...@@ -14788,23 +14787,24 @@ mysql> select STRCMP('text', 'text'); ...@@ -14788,23 +14787,24 @@ mysql> select STRCMP('text', 'text');
@code{MATCH ... AGAINST()} is used for full-text search and returns @code{MATCH ... AGAINST()} is used for full-text search and returns
relevance - similarity measure between the text in columns relevance - similarity measure between the text in columns
@code{(col1,col2,...)} and the query @code{expr}. Relevance is a @code{(col1,col2,...)} and the query @code{expr}. Relevance is a
positive floating point number. Zero relevance means no similarity. positive floating-point number. Zero relevance means no similarity.
For @code{MATCH ... AGAINST()} to work, a @strong{FULLTEXT} index For @code{MATCH ... AGAINST()} to work, a @strong{FULLTEXT} index
must be created first. @xref{CREATE TABLE, , @code{CREATE TABLE}}. must be created first. @xref{CREATE TABLE, , @code{CREATE TABLE}}.
@code{MATCH ... AGAINST()} is available in @strong{MySQL} 3.23.23 or later. @code{MATCH ... AGAINST()} is available in @strong{MySQL} Version
For details and usage examples see @xref{MySQL full-text search}. 3.23.23 or later. For details and usage examples
@pxref{MySQL full-text search}.
@end table @end table
@findex Casts @findex Casts
@node Casts, Control flow functions, String comparison functions, Functions @node Casts, Control flow functions, String comparison functions, Functions
@subsection Cast operators @subsection Cast Operators
@table @code @table @code
@findex BINARY @findex BINARY
@item @code{BINARY} @item @code{BINARY}
The @code{BINARY} operator casts the string following it to a binary string. The @code{BINARY} operator casts the string following it to a binary string.
This is an easy way to force a column comparison to be case sensitive even This is an easy way to force a column comparison to be case sensitive even
if the column isn't defined as @code{BINARY} or @code{BLOB}. if the column isn't defined as @code{BINARY} or @code{BLOB}:
@example @example
mysql> select "a" = "A"; mysql> select "a" = "A";
-> 1 -> 1
...@@ -14812,20 +14812,20 @@ mysql> select BINARY "a" = "A"; ...@@ -14812,20 +14812,20 @@ mysql> select BINARY "a" = "A";
-> 0 -> 0
@end example @end example
@code{BINARY} was introduced in @strong{MySQL} 3.23.0 @code{BINARY} was introduced in @strong{MySQL} 3.23.0.
@end table @end table
@findex Control flow functions @findex Control flow functions
@findex Functions, control flow @findex Functions, control flow
@node Control flow functions, Mathematical functions, Casts, Functions @node Control flow functions, Mathematical functions, Casts, Functions
@subsection Control flow functions @subsection Control Flow Functions
@table @code @table @code
@findex IFNULL() @findex IFNULL()
@item IFNULL(expr1,expr2) @item IFNULL(expr1,expr2)
If @code{expr1} is not @code{NULL}, @code{IFNULL()} returns @code{expr1}, If @code{expr1} is not @code{NULL}, @code{IFNULL()} returns @code{expr1},
else it returns @code{expr2}. @code{IFNULL()} returns a numeric or string else it returns @code{expr2}. @code{IFNULL()} returns a numeric or string
value, depending on the context in which it is used. value, depending on the context in which it is used:
@example @example
mysql> select IFNULL(1,0); mysql> select IFNULL(1,0);
-> 1 -> 1
...@@ -14840,7 +14840,7 @@ mysql> select IFNULL(1/0,'yes'); ...@@ -14840,7 +14840,7 @@ mysql> select IFNULL(1/0,'yes');
@findex NULLIF() @findex NULLIF()
@item NULLIF(expr1,expr2) @item NULLIF(expr1,expr2)
If @code{expr1 = expr2} is true, return @code{NULL} else return @code{expr1}. If @code{expr1 = expr2} is true, return @code{NULL} else return @code{expr1}.
This is the same as @code{CASE WHEN x = y THEN NULL ELSE x END} This is the same as @code{CASE WHEN x = y THEN NULL ELSE x END}:
@example @example
mysql> select NULLIF(1,1); mysql> select NULLIF(1,1);
-> NULL -> NULL
...@@ -14856,7 +14856,7 @@ are equal. ...@@ -14856,7 +14856,7 @@ are equal.
If @code{expr1} is TRUE (@code{expr1 <> 0} and @code{expr1 <> NULL}) then If @code{expr1} is TRUE (@code{expr1 <> 0} and @code{expr1 <> NULL}) then
@code{IF()} returns @code{expr2}, else it returns @code{expr3}. @code{IF()} returns @code{expr2}, else it returns @code{expr3}.
@code{IF()} returns a numeric or string value, depending on the context @code{IF()} returns a numeric or string value, depending on the context
in which it is used. in which it is used:
@example @example
mysql> select IF(1>2,2,3); mysql> select IF(1>2,2,3);
...@@ -14869,7 +14869,7 @@ mysql> select IF(strcmp('test','test1'),'no','yes'); ...@@ -14869,7 +14869,7 @@ mysql> select IF(strcmp('test','test1'),'no','yes');
@code{expr1} is evaluated as an integer value, which means that if you are @code{expr1} is evaluated as an integer value, which means that if you are
testing floating-point or string values, you should do so using a comparison testing floating-point or string values, you should do so using a comparison
operation. operation:
@example @example
mysql> select IF(0.1,1,0); mysql> select IF(0.1,1,0);
...@@ -14884,10 +14884,10 @@ may not be what you expect. In the second case, the comparison tests the ...@@ -14884,10 +14884,10 @@ may not be what you expect. In the second case, the comparison tests the
original floating-point value to see whether it is non-zero. The result original floating-point value to see whether it is non-zero. The result
of the comparison is used as an integer. of the comparison is used as an integer.
The default return type of @code{IF()} (which may matter when it stored into The default return type of @code{IF()} (which may matter when it is stored into
a temporary table) is calculated in @strong{MySQL} 3.23 as follows: a temporary table) is calculated in @strong{MySQL} Version 3.23 as follows:
@multitable @columnfractions .7 .3 @multitable @columnfractions .55 .45
@item @strong{Expression} @tab @strong{Return value} @item @strong{Expression} @tab @strong{Return value}
@item expr2 or expr3 returns string @tab string @item expr2 or expr3 returns string @tab string
@item expr2 or expr3 returns a floating point value @tab floating point @item expr2 or expr3 returns a floating point value @tab floating point
...@@ -14900,9 +14900,9 @@ a temporary table) is calculated in @strong{MySQL} 3.23 as follows: ...@@ -14900,9 +14900,9 @@ a temporary table) is calculated in @strong{MySQL} 3.23 as follows:
The first version returns the @code{result} where The first version returns the @code{result} where
@code{value=compare-value}. The second version returns the result for @code{value=compare-value}. The second version returns the result for
the first condition which is true. If there was no matching result the first condition, which is true. If there was no matching result
value, then the result after @code{ELSE} is returned. If there is no value, then the result after @code{ELSE} is returned. If there is no
@code{ELSE} part then @code{NULL} is returned. @code{ELSE} part then @code{NULL} is returned:
@example @example
mysql> SELECT CASE 1 WHEN 1 THEN "one" WHEN 2 THEN "two" ELSE "more" END; mysql> SELECT CASE 1 WHEN 1 THEN "one" WHEN 2 THEN "two" ELSE "more" END;
...@@ -14917,7 +14917,7 @@ mysql> SELECT CASE BINARY "B" when "a" then 1 when "b" then 2 END; ...@@ -14917,7 +14917,7 @@ mysql> SELECT CASE BINARY "B" when "a" then 1 when "b" then 2 END;
@findex Mathematical functions @findex Mathematical functions
@findex Functions, mathematical @findex Functions, mathematical
@node Mathematical functions, String functions, Control flow functions, Functions @node Mathematical functions, String functions, Control flow functions, Functions
@subsection Mathematical functions @subsection Mathematical Functions
All mathematical functions return @code{NULL} in case of an error. All mathematical functions return @code{NULL} in case of an error.
@table @code @table @code
...@@ -14925,7 +14925,7 @@ All mathematical functions return @code{NULL} in case of an error. ...@@ -14925,7 +14925,7 @@ All mathematical functions return @code{NULL} in case of an error.
@findex minus, unary (-) @findex minus, unary (-)
@findex unary minus (-) @findex unary minus (-)
@item - @item -
Unary minus. Changes the sign of the argument. Unary minus. Changes the sign of the argument:
@example @example
mysql> select - 2; mysql> select - 2;
-> -2 -> -2
...@@ -14937,7 +14937,7 @@ may have the value of @code{-2^63}! ...@@ -14937,7 +14937,7 @@ may have the value of @code{-2^63}!
@findex ABS() @findex ABS()
@item ABS(X) @item ABS(X)
Returns the absolute value of @code{X}. Returns the absolute value of @code{X}:
@example @example
mysql> select ABS(2); mysql> select ABS(2);
-> 2 -> 2
...@@ -14949,8 +14949,8 @@ This function is safe to use with @code{BIGINT} values. ...@@ -14949,8 +14949,8 @@ This function is safe to use with @code{BIGINT} values.
@findex SIGN() @findex SIGN()
@item SIGN(X) @item SIGN(X)
Returns the sign of the argument as @code{-1}, @code{0} or @code{1}, depending Returns the sign of the argument as @code{-1}, @code{0}, or @code{1}, depending
on whether @code{X} is negative, zero, or positive. on whether @code{X} is negative, zero, or positive:
@example @example
mysql> select SIGN(-32); mysql> select SIGN(-32);
-> -1 -> -1
...@@ -14966,7 +14966,7 @@ mysql> select SIGN(234); ...@@ -14966,7 +14966,7 @@ mysql> select SIGN(234);
@item MOD(N,M) @item MOD(N,M)
@itemx % @itemx %
Modulo (like the @code{%} operator in C). Modulo (like the @code{%} operator in C).
Returns the remainder of @code{N} divided by @code{M}. Returns the remainder of @code{N} divided by @code{M}:
@example @example
mysql> select MOD(234, 10); mysql> select MOD(234, 10);
-> 4 -> 4
...@@ -14980,7 +14980,7 @@ This function is safe to use with @code{BIGINT} values. ...@@ -14980,7 +14980,7 @@ This function is safe to use with @code{BIGINT} values.
@findex FLOOR() @findex FLOOR()
@item FLOOR(X) @item FLOOR(X)
Returns the largest integer value not greater than @code{X}. Returns the largest integer value not greater than @code{X}:
@example @example
mysql> select FLOOR(1.23); mysql> select FLOOR(1.23);
-> 1 -> 1
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment