(We had to use the @code{:=} syntax here, because @code{=} was reserved for
comparisons.)
User variables may be used where expressions are allowed. Note that
User variables may be used where expressions are allowed. Note that
this does not currently include use in contexts where a number is explicitly
this does not currently include contexts where a number is explicitly
required, such as in the @code{LIMIT} clause of a @code{SELECT} statement,
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 evaluated
evaluated when it's sent to the client. This means that in the @code{HAVING},
only when it's sent to the client. This means that in the @code{HAVING},
@code{GROUP BY}, or @code{ORDER BY} clause, you can't refer to an expression
@code{GROUP BY}, or @code{ORDER BY} clause, you can't refer to an expression
that involves variables that are set in the @code{SELECT} part. For example,
that involves variables that are set in the @code{SELECT} part. For example,
the following statement will NOT work as expected:
the following statement will NOT work as expected:
...
@@ -28185,8 +28190,8 @@ multiple-line comment
...
@@ -28185,8 +28190,8 @@ multiple-line comment
1;
1;
@end example
@end example
Note that the @code{--} comment style requires you to have at least one space
Note that the @code{--} (double-dash) comment style requires you to have at
after the @code{--}!
least one space after the second dash!
Although the server understands the comment syntax just described,
Although the server understands the comment syntax just described,
there are some limitations on the way that the @code{mysql} client
there are some limitations on the way that the @code{mysql} client
...
@@ -28210,8 +28215,8 @@ These limitations apply both when you run @code{mysql} interactively
...
@@ -28210,8 +28215,8 @@ These limitations apply both when you run @code{mysql} interactively
and when you put commands in a file and tell @code{mysql} to read its
and when you put commands in a file and tell @code{mysql} to read its
input from that file with @code{mysql < some-file}.
input from that file with @code{mysql < some-file}.
MySQL only supports the @samp{--} ANSI SQL comment style if it is
MySQL supports the @samp{--} ANSI SQL comment style only if the second dash
followed by a space. @xref{ANSI diff comments}.
is followed by a space. @xref{ANSI diff comments}.
@node Reserved words, , Comments, Language Structure
@node Reserved words, , Comments, Language Structure
...
@@ -28224,12 +28229,12 @@ A common problem stems from trying to create a table with column names that
...
@@ -28224,12 +28229,12 @@ A common problem stems from trying to create a table with column names that
use the names of datatypes or functions built into MySQL, such as
use the names of datatypes or functions built into MySQL, such as
@code{TIMESTAMP} or @code{GROUP}. You're allowed to do it (for example,
@code{TIMESTAMP} or @code{GROUP}. You're allowed to do it (for example,
@code{ABS} is an allowed column name), but whitespace is not allowed between
@code{ABS} is an allowed column name), but whitespace is not allowed between
a function name and the @samp{(} when using functions whose names are also
a function name and the immediately following @samp{(} when using functions
column names.
whose names are also column names.
The following words are explicitly reserved in MySQL. Most of
The following words are explicitly reserved in MySQL. Most of
them are forbidden by ANSI SQL92 as column and/or table names
them are forbidden by ANSI SQL92 as column and/or table names
(for example, @code{group}).
(for example, @code{GROUP}).
A few are reserved because MySQL needs them and is
A few are reserved because MySQL needs them and is
(currently) using a @code{yacc} parser:
(currently) using a @code{yacc} parser:
...
@@ -28440,12 +28445,12 @@ A large integer. The signed range is @code{-9223372036854775808} to
...
@@ -28440,12 +28445,12 @@ A large integer. The signed range is @code{-9223372036854775808} to
@code{9223372036854775807}. The unsigned range is @code{0} to
@code{9223372036854775807}. The unsigned range is @code{0} to
@code{18446744073709551615}.
@code{18446744073709551615}.
Some things you should be aware about @code{BIGINT} columns:
Some things you should be aware of with respect to @code{BIGINT} columns:
@itemize @bullet
@itemize @bullet
@item
@item
@cindex rounding errors
@cindex rounding errors
As all arithmetic is done using signed @code{BIGINT} or @code{DOUBLE}
All arithmetic is done using signed @code{BIGINT} or @code{DOUBLE}
values, so you shouldn't use unsigned big integers larger than
values, so you shouldn't use unsigned big integers larger than
@code{9223372036854775807} (63 bits) except with bit functions! If you
@code{9223372036854775807} (63 bits) except with bit functions! If you
do that, some of the last digits in the result may be wrong because of
do that, some of the last digits in the result may be wrong because of
...
@@ -28458,17 +28463,17 @@ Use integers to store big unsigned values in a @code{BIGINT} column.
...
@@ -28458,17 +28463,17 @@ Use integers to store big unsigned values in a @code{BIGINT} column.
@item
@item
In @code{MIN(big_int_column)} and @code{MAX(big_int_column)}.
In @code{MIN(big_int_column)} and @code{MAX(big_int_column)}.
@item
@item
When using operators (@code{+}, @code{-}, @code{*} etc) where
When using operators (@code{+}, @code{-}, @code{*}, etc.) where
both operands are integers.
both operands are integers.
@end itemize
@end itemize
@item
@item
You can always store an exact integer value in a @code{BIGINT} column by
You can always store an exact integer value in a @code{BIGINT} column by
storing it as a string, as there is in this case there will be no
storing it as a string. In this case, MySQL will perform a string-to-number
intermediate double representation.
conversion that involves no intermediate double representation.
@item
@item
@samp{-}, @samp{+}, and @samp{*} will use @code{BIGINT} arithmetic when
@samp{-}, @samp{+}, and @samp{*} will use @code{BIGINT} arithmetic when
both arguments are @code{INTEGER} values! This means that if you
both arguments are integer values! This means that if you
multiply two big integers (or results from functions that return
multiply two big integers (or results from functions that return
integers) you may get unexpected results when the result is larger than
integers) you may get unexpected results when the result is larger than
@code{9223372036854775807}.
@code{9223372036854775807}.
...
@@ -28504,7 +28509,7 @@ This syntax is provided for ODBC compatibility.
...
@@ -28504,7 +28509,7 @@ 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 @code{M} is the display width and @code{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.
...
@@ -28515,10 +28520,10 @@ number of decimals. @code{FLOAT} without an argument or with an argument of
...
@@ -28515,10 +28520,10 @@ 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
is the display width and D is the number of decimals. @code{DOUBLE}
@code{M} is the display width and @code{D} is the number of decimals.
without an argument or @code{FLOAT(X)} where 25 <= X <= 53 stands for a
@code{DOUBLE} without an argument or @code{FLOAT(X)} where 25 <= @code{X}
double-precision floating-point number.
<= 53 stands for a double-precision floating-point number.
@tindex DOUBLE PRECISION
@tindex DOUBLE PRECISION
@tindex REAL
@tindex REAL
...
@@ -28533,17 +28538,18 @@ These are synonyms for @code{DOUBLE}.
...
@@ -28533,17 +28538,18 @@ 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 and,
using one character for each digit of the value. The decimal point and,
for negative numbers, the @samp{-} sign, are not counted in M (but space
for negative numbers, the @samp{-} sign, are not counted in @code{M} (but
for these are reserved). If @code{D} is 0, values will have no decimal
space for these is reserved). If @code{D} is 0, values will have no decimal
point or fractional part. The maximum range of @code{DECIMAL} values is
point or fractional part. The maximum range of @code{DECIMAL} values is
the same as for @code{DOUBLE}, but the actual range for a given
the same as for @code{DOUBLE}, but the actual range for a given
@code{DECIMAL} column may be constrained by the choice of @code{M} and
@code{DECIMAL} column may be constrained by the choice of @code{M} and
@code{D}.
@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 omitted, the default is 0. If @code{M} is omitted, the
default is 10.
Note that in MySQL Version 3.22 the @code{M} argument had to
Prior to MySQL Version 3.23, the @code{M} argument must include the space
includes the space needed for the sign and the decimal point.
needed for the sign and the decimal point.
@tindex NUMERIC
@tindex NUMERIC
@item NUMERIC(M,D) [ZEROFILL]
@item NUMERIC(M,D) [ZEROFILL]
...
@@ -28582,14 +28588,14 @@ recent operation if you don't give it a value yourself. You can also set it
...
@@ -28582,14 +28588,14 @@ 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
The @code{M} argument affects only how a @code{TIMESTAMP} column is displayed;
affects how the @code{TIMESTAMP} column is displayed.
its values always are stored using 4 bytes each.
Note that @code{TIMESTAMP(X)} columns where X is 8 or 14 are reported to
Note that @code{TIMESTAMP(M)} columns where @code{M} 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(M)} columns are reported to be
strings. This is just to ensure that one can reliably 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!
@xref{DATETIME}.
@xref{DATETIME, , @code{DATETIME}}.
@tindex TIME
@tindex TIME
@item TIME
@item TIME
...
@@ -28597,7 +28603,7 @@ the table with these types!
...
@@ -28597,7 +28603,7 @@ the table with these types!
A time. The range is @code{'-838:59:59'} to @code{'838:59:59'}.
A time. The range is @code{'-838:59:59'} to @code{'838:59:59'}.
MySQL displays @code{TIME} values in @code{'HH:MM:SS'} format, but
MySQL displays @code{TIME} values in @code{'HH:MM:SS'} format, but
allows you to assign values to @code{TIME} columns using either strings or
allows you to assign values to @code{TIME} columns using either strings or
numbers. @xref{TIME}.
numbers. @xref{TIME, , @code{TIME}}.
@tindex YEAR
@tindex YEAR
@item YEAR[(2|4)]
@item YEAR[(2|4)]
...
@@ -28607,7 +28613,7 @@ are @code{1901} to @code{2155}, @code{0000} in the 4-digit year format,
...
@@ -28607,7 +28613,7 @@ are @code{1901} to @code{2155}, @code{0000} in the 4-digit year format,
and 1970-2069 if you use the 2-digit format (70-69). MySQL displays
and 1970-2069 if you use the 2-digit format (70-69). MySQL displays
@code{YEAR} values in @code{YYYY} format, but allows you to assign values to
@code{YEAR} values in @code{YYYY} format, but allows you to assign values to
@code{YEAR} columns using either strings or numbers. (The @code{YEAR} type is
@code{YEAR} columns using either strings or numbers. (The @code{YEAR} type is
new in MySQL Version 3.22.) @xref{YEAR}.
unavailable prior to MySQL Version 3.22.) @xref{YEAR, , @code{YEAR}}.
@tindex NATIONAL CHAR
@tindex NATIONAL CHAR
@tindex NCHAR
@tindex NCHAR
...
@@ -28616,14 +28622,15 @@ new in MySQL Version 3.22.) @xref{YEAR}.
...
@@ -28616,14 +28622,15 @@ new in MySQL Version 3.22.) @xref{YEAR}.
@item [NATIONAL] CHAR(M) [BINARY]
@item [NATIONAL] CHAR(M) [BINARY]
A fixed-length string that is always right-padded with spaces to the
A fixed-length string that is always right-padded with spaces to the
specified length when stored. The range of @code{M} is 1 to 255 characters.
specified length when stored. The range of @code{M} is 0 to 255 characters
(1 to 255 prior to MySQL Version 3.23).
Trailing spaces are removed when the value is retrieved. @code{CHAR} values
Trailing spaces are removed when the value is retrieved. @code{CHAR} values
are sorted and compared in case-insensitive fashion according to the
are sorted and compared in case-insensitive fashion according to the
default character set unless the @code{BINARY} keyword is given.
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} (or its equivalent short form, @code{NCHAR}) is the
define that a CHAR column should use the default CHARACTER set. This is
ANSI SQL way to define that a @code{CHAR} column should use the default
the default in MySQL.
CHARACTER set. This is the default in MySQL.
@code{CHAR} is a shorthand for @code{CHARACTER}.
@code{CHAR} is a shorthand for @code{CHARACTER}.
...
@@ -28632,8 +28639,8 @@ MySQL allows you to create a column of type
...
@@ -28632,8 +28639,8 @@ MySQL allows you to create a column of type
some old applications that depend on the existence of a column but that do not
some old applications that depend on the existence of a column but that do not
actually use the value. This is also quite nice when you need a
actually use the value. This is also quite nice when you need a
column that only can take 2 values: A @code{CHAR(0)}, that is not defined
column that only can take 2 values: A @code{CHAR(0)}, that is not defined
as @code{NOT NULL}, will only occupy one bit and can only take 2 values:
as @code{NOT NULL}, will occupy only one bit and can take only 2 values:
@code{NULL} or @code{""}. @xref{CHAR}.
@code{NULL} or @code{""}. @xref{CHAR, , @code{CHAR}}.
@tindex BOOL
@tindex BOOL
@tindex BIT
@tindex BIT
...
@@ -35026,7 +35033,7 @@ The options work for all table types, if not otherwise indicated:
...
@@ -35026,7 +35033,7 @@ The options work for all table types, if not otherwise indicated:
@item @code{MAX_ROWS} @tab Max number of rows you plan to store in the table.
@item @code{MAX_ROWS} @tab Max number of rows you plan to store in the table.
@item @code{MIN_ROWS} @tab Minimum number of rows you plan to store in the table.
@item @code{MIN_ROWS} @tab Minimum number of rows you plan to store in the table.
@item @code{PACK_KEYS} @tab Set this to 1 if you want to have a smaller index. This usually makes updates slower and reads faster (MyISAM, ISAM). Setting this to 0 will disable all packing of keys. Setting this to @code{DEFAULT} (MySQL 4.0) will tell the table handler to only pack long @code{CHAR}/@code{VARCHAR} columns.
@item @code{PACK_KEYS} @tab Set this to 1 if you want to have a smaller index. This usually makes updates slower and reads faster (MyISAM, ISAM). Setting this to 0 will disable all packing of keys. Setting this to @code{DEFAULT} (MySQL 4.0) will tell the table handler to only pack long @code{CHAR}/@code{VARCHAR} columns.
@item @code{PASSWORD} @tab Encrypt the @code{.frm} file with a password. This option doesn't do anything in the standard MySQL version.
@item @code{PASSWORD} @tab Encrypt the @file{.frm} file with a password. This option doesn't do anything in the standard MySQL version.
@item @code{DELAY_KEY_WRITE} @tab Set this to 1 if want to delay key table updates until the table is closed (MyISAM).
@item @code{DELAY_KEY_WRITE} @tab Set this to 1 if want to delay key table updates until the table is closed (MyISAM).
@item @code{ROW_FORMAT} @tab Defines how the rows should be stored. Currently this option only works with MyISAM tables, which supports the @code{DYNAMIC} and @code{FIXED} row formats. @xref{MyISAM table formats}.
@item @code{ROW_FORMAT} @tab Defines how the rows should be stored. Currently this option only works with MyISAM tables, which supports the @code{DYNAMIC} and @code{FIXED} row formats. @xref{MyISAM table formats}.
@end multitable
@end multitable
...
@@ -36510,7 +36517,7 @@ or @code{BDB}), depending on how you compile it.
...
@@ -36510,7 +36517,7 @@ or @code{BDB}), depending on how you compile it.
When you create a new table, you can tell MySQL which table
When you create a new table, you can tell MySQL which table
type it should use for the table. MySQL will always create a
type it should use for the table. MySQL will always create a
@code{.frm} file to hold the table and column definitions. Depending on
@file{.frm} file to hold the table and column definitions. Depending on
the table type, the index and data will be stored in other files.
the table type, the index and data will be stored in other files.
Note that to use @code{InnoDB} tables you have to use at least
Note that to use @code{InnoDB} tables you have to use at least
...
@@ -36583,8 +36590,8 @@ of both worlds.
...
@@ -36583,8 +36590,8 @@ of both worlds.
@code{MyISAM} is the default table type in MySQL Version 3.23. It's
@code{MyISAM} is the default table type in MySQL Version 3.23. It's
based on the @code{ISAM} code and has a lot of useful extensions.
based on the @code{ISAM} code and has a lot of useful extensions.
The index is stored in a file with the @code{.MYI} (MYIndex) extension,
The index is stored in a file with the @file{.MYI} (MYIndex) extension,
and the data is stored in a file with the @code{.MYD} (MYData) extension.
and the data is stored in a file with the @file{.MYD} (MYData) extension.
You can check/repair @code{MyISAM} tables with the @code{myisamchk}
You can check/repair @code{MyISAM} tables with the @code{myisamchk}
utility. @xref{Crash recovery}. You can compress @code{MyISAM} tables with
utility. @xref{Crash recovery}. You can compress @code{MyISAM} tables with
@code{myisampack} to take up much less space. @xref{myisampack}.
@code{myisampack} to take up much less space. @xref{myisampack}.
...
@@ -37018,7 +37025,7 @@ case of this. @xref{Reproduceable test case}.
...
@@ -37018,7 +37025,7 @@ case of this. @xref{Reproduceable test case}.