Commit 9c0b3474 authored by unknown's avatar unknown

manual.texi More SQL keyword capping.


Docs/manual.texi:
  More SQL keyword capping.
parent 953e3487
...@@ -3499,7 +3499,7 @@ You can't use temporary tables more than once in the same query. ...@@ -3499,7 +3499,7 @@ You can't use temporary tables more than once in the same query.
For example, the following doesn't work. For example, the following doesn't work.
@example @example
select * from temporary_table, temporary_table as t2; mysql> SELECT * FROM temporary_table, temporary_table AS t2;
@end example @end example
@item @item
...@@ -3899,7 +3899,7 @@ Allow update of variables in @code{UPDATE} statements. For example: ...@@ -3899,7 +3899,7 @@ Allow update of variables in @code{UPDATE} statements. For example:
@item @item
Change when user variables are updated so that one can use them with Change when user variables are updated so that one can use them with
@code{GROUP BY}, as in the following example: @code{GROUP BY}, as in the following example:
@code{SELECT id, @@a:=count(*), sum(sum_col)/@@a FROM table_name GROUP BY id}. @code{SELECT id, @@a:=COUNT(*), SUM(sum_col)/@@a FROM table_name GROUP BY id}.
@item @item
Don't add automatic @code{DEFAULT} values to columns. Give an error when using Don't add automatic @code{DEFAULT} values to columns. Give an error when using
an @code{INSERT} that doesn't contain a column that doesn't have a an @code{INSERT} that doesn't contain a column that doesn't have a
...@@ -3930,7 +3930,7 @@ Make @code{LOAD DATA INFILE} understand syntax like: ...@@ -3930,7 +3930,7 @@ Make @code{LOAD DATA INFILE} understand syntax like:
@example @example
LOAD DATA INFILE 'file_name.txt' INTO TABLE tbl_name LOAD DATA INFILE 'file_name.txt' INTO TABLE tbl_name
TEXT_FIELDS (text_field1, text_field2, text_field3) TEXT_FIELDS (text_field1, text_field2, text_field3)
SET table_field1=concatenate(text_field1, text_field2), SET table_field1=CONCAT(text_field1, text_field2),
table_field3=23 table_field3=23
IGNORE text_field3 IGNORE text_field3
@end example @end example
...@@ -3977,7 +3977,7 @@ should be implemented. ...@@ -3977,7 +3977,7 @@ should be implemented.
@item @item
@code{NATURAL JOIN}. @code{NATURAL JOIN}.
@item @item
Allow @code{select a from crash_me left join crash_me2 using (a)}; In this Allow @code{SELECT a FROM crash_me LEFT JOIN crash_me2 USING (a)}; In this
case @code{a} is assumed to come from the @code{crash_me} table. case @code{a} is assumed to come from the @code{crash_me} table.
@item @item
Fix that @code{ON} and @code{USING} works with the @code{JOIN} Fix that @code{ON} and @code{USING} works with the @code{JOIN}
...@@ -4031,10 +4031,10 @@ value <> 0 -> TRUE. ...@@ -4031,10 +4031,10 @@ value <> 0 -> TRUE.
@item @item
Fix that the type for @code{MAX(column)} is the same as the column type. Fix that the type for @code{MAX(column)} is the same as the column type.
@example @example
create table t1 (a DATE); mysql> CREATE TABLE t1 (a DATE);
insert into t1 values (now()); mysql> INSERT INTO t1 VALUES (NOW());
create table t2 select MAX(a) from t1; mysql> CREATE TABLE t2 SELECT MAX(a) FROM t1;
show columns from t2; mysql> SHOW COLUMNS FROM t2;
@end example @end example
@item @item
Come up with a nice syntax for a statement that will @code{UPDATE} the row Come up with a nice syntax for a statement that will @code{UPDATE} the row
...@@ -7664,7 +7664,7 @@ Database: mysql ...@@ -7664,7 +7664,7 @@ Database: mysql
| user | | user |
+--------------+ +--------------+
shell> BINDIR/mysql -e "select host,db,user from db" mysql shell> BINDIR/mysql -e "SELECT host,db,user FROM db" mysql
+------+--------+------+ +------+--------+------+
| host | db | user | | host | db | user |
+------+--------+------+ +------+--------+------+
...@@ -11578,7 +11578,7 @@ prompt and press Enter: ...@@ -11578,7 +11578,7 @@ prompt and press Enter:
@example @example
mysql> SELECT VERSION(), CURRENT_DATE; mysql> SELECT VERSION(), CURRENT_DATE;
+--------------+--------------+ +--------------+--------------+
| version() | CURRENT_DATE | | VERSION() | CURRENT_DATE |
+--------------+--------------+ +--------------+--------------+
| 3.22.20a-log | 1999-03-19 | | 3.22.20a-log | 1999-03-19 |
+--------------+--------------+ +--------------+--------------+
...@@ -11644,7 +11644,7 @@ Just end each one with a semicolon: ...@@ -11644,7 +11644,7 @@ Just end each one with a semicolon:
@example @example
mysql> SELECT VERSION(); SELECT NOW(); mysql> SELECT VERSION(); SELECT NOW();
+--------------+ +--------------+
| version() | | VERSION() |
+--------------+ +--------------+
| 3.22.20a-log | | 3.22.20a-log |
+--------------+ +--------------+
...@@ -13439,9 +13439,8 @@ For example, to find the articles with the highest and lowest price you ...@@ -13439,9 +13439,8 @@ For example, to find the articles with the highest and lowest price you
can do: can do:
@example @example
select @@min_price:=min(price),@@max_price:=max(price) from shop; mysql> SELECT @@min_price:=MIN(price),@@max_price:=MAX(price) FROM shop;
select * from shop where price=@@min_price or price=@@max_price; mysql> SELECT * FROM shop WHERE price=@@min_price OR price=@@max_price;
+---------+--------+-------+ +---------+--------+-------+
| article | dealer | price | | article | dealer | price |
+---------+--------+-------+ +---------+--------+-------+
...@@ -13663,8 +13662,8 @@ Which returns: ...@@ -13663,8 +13662,8 @@ Which returns:
+--------+----+---------+ +--------+----+---------+
@end example @end example
Note that in this case, the auto_increment value will be reused if you Note that in this case, the @code{AUTO_INCREMENT} value will be reused if you
delete the row with the biggest auto_increment value in any group. delete the row with the biggest @code{AUTO_INCREMENT} value in any group.
You can get the used @code{AUTO_INCREMENT} key with the You can get the used @code{AUTO_INCREMENT} key with the
@code{LAST_INSERT_ID()} SQL function or the @code{mysql_insert_id()} API @code{LAST_INSERT_ID()} SQL function or the @code{mysql_insert_id()} API
...@@ -13832,96 +13831,96 @@ The following query is used to determine who goes into the second part of the ...@@ -13832,96 +13831,96 @@ The following query is used to determine who goes into the second part of the
project: project:
@example @example
select SELECT
concat(p1.id, p1.tvab) + 0 as tvid, CONCAT(p1.id, p1.tvab) + 0 AS tvid,
concat(p1.christian_name, " ", p1.surname) as Name, CONCAT(p1.christian_name, " ", p1.surname) AS Name,
p1.postal_code as Code, p1.postal_code AS Code,
p1.city as City, p1.city AS City,
pg.abrev as Area, pg.abrev AS Area,
if(td.participation = "Aborted", "A", " ") as A, IF(td.participation = "Aborted", "A", " ") AS A,
p1.dead as dead1, p1.dead AS dead1,
l.event as event1, l.event AS event1,
td.suspect as tsuspect1, td.suspect AS tsuspect1,
id.suspect as isuspect1, id.suspect AS isuspect1,
td.severe as tsevere1, td.severe AS tsevere1,
id.severe as isevere1, id.severe AS isevere1,
p2.dead as dead2, p2.dead AS dead2,
l2.event as event2, l2.event AS event2,
h2.nurse as nurse2, h2.nurse AS nurse2,
h2.doctor as doctor2, h2.doctor AS doctor2,
td2.suspect as tsuspect2, td2.suspect AS tsuspect2,
id2.suspect as isuspect2, id2.suspect AS isuspect2,
td2.severe as tsevere2, td2.severe AS tsevere2,
id2.severe as isevere2, id2.severe AS isevere2,
l.finish_date l.finish_date
from FROM
twin_project as tp twin_project AS tp
/* For Twin 1 */ /* For Twin 1 */
left join twin_data as td on tp.id = td.id LEFT JOIN twin_data AS td ON tp.id = td.id
and tp.tvab = td.tvab AND tp.tvab = td.tvab
left join informant_data as id on tp.id = id.id LEFT JOIN informant_data AS id ON tp.id = id.id
and tp.tvab = id.tvab AND tp.tvab = id.tvab
left join harmony as h on tp.id = h.id LEFT JOIN harmony AS h ON tp.id = h.id
and tp.tvab = h.tvab AND tp.tvab = h.tvab
left join lentus as l on tp.id = l.id LEFT JOIN lentus AS l ON tp.id = l.id
and tp.tvab = l.tvab AND tp.tvab = l.tvab
/* For Twin 2 */ /* For Twin 2 */
left join twin_data as td2 on p2.id = td2.id LEFT JOIN twin_data AS td2 ON p2.id = td2.id
and p2.tvab = td2.tvab AND p2.tvab = td2.tvab
left join informant_data as id2 on p2.id = id2.id LEFT JOIN informant_data AS id2 ON p2.id = id2.id
and p2.tvab = id2.tvab AND p2.tvab = id2.tvab
left join harmony as h2 on p2.id = h2.id LEFT JOIN harmony AS h2 ON p2.id = h2.id
and p2.tvab = h2.tvab AND p2.tvab = h2.tvab
left join lentus as l2 on p2.id = l2.id LEFT JOIN lentus AS l2 ON p2.id = l2.id
and p2.tvab = l2.tvab, AND p2.tvab = l2.tvab,
person_data as p1, person_data AS p1,
person_data as p2, person_data AS p2,
postal_groups as pg postal_groups AS pg
where WHERE
/* p1 gets main twin and p2 gets his/her twin. */ /* p1 gets main twin and p2 gets his/her twin. */
/* ptvab is a field inverted from tvab */ /* ptvab is a field inverted from tvab */
p1.id = tp.id and p1.tvab = tp.tvab and p1.id = tp.id AND p1.tvab = tp.tvab AND
p2.id = p1.id and p2.ptvab = p1.tvab and p2.id = p1.id AND p2.ptvab = p1.tvab AND
/* Just the sceening survey */ /* Just the sceening survey */
tp.survey_no = 5 and tp.survey_no = 5 AND
/* Skip if partner died before 65 but allow emigration (dead=9) */ /* Skip if partner died before 65 but allow emigration (dead=9) */
(p2.dead = 0 or p2.dead = 9 or (p2.dead = 0 OR p2.dead = 9 OR
(p2.dead = 1 and (p2.dead = 1 AND
(p2.death_date = 0 or (p2.death_date = 0 OR
(((to_days(p2.death_date) - to_days(p2.birthday)) / 365) (((TO_DAYS(p2.death_date) - TO_DAYS(p2.birthday)) / 365)
>= 65)))) >= 65))))
and AND
( (
/* Twin is suspect */ /* Twin is suspect */
(td.future_contact = 'Yes' and td.suspect = 2) or (td.future_contact = 'Yes' AND td.suspect = 2) OR
/* Twin is suspect - Informant is Blessed */ /* Twin is suspect - Informant is Blessed */
(td.future_contact = 'Yes' and td.suspect = 1 (td.future_contact = 'Yes' AND td.suspect = 1
and id.suspect = 1) or AND id.suspect = 1) OR
/* No twin - Informant is Blessed */ /* No twin - Informant is Blessed */
(ISNULL(td.suspect) and id.suspect = 1 (ISNULL(td.suspect) AND id.suspect = 1
and id.future_contact = 'Yes') or AND id.future_contact = 'Yes') OR
/* Twin broken off - Informant is Blessed */ /* Twin broken off - Informant is Blessed */
(td.participation = 'Aborted' (td.participation = 'Aborted'
and id.suspect = 1 and id.future_contact = 'Yes') or AND id.suspect = 1 AND id.future_contact = 'Yes') OR
/* Twin broken off - No inform - Have partner */ /* Twin broken off - No inform - Have partner */
(td.participation = 'Aborted' and ISNULL(id.suspect) (td.participation = 'Aborted' AND ISNULL(id.suspect)
and p2.dead = 0)) AND p2.dead = 0))
and AND
l.event = 'Finished' l.event = 'Finished'
/* Get at area code */ /* Get at area code */
and substring(p1.postal_code, 1, 2) = pg.code AND SUBSTRING(p1.postal_code, 1, 2) = pg.code
/* Not already distributed */ /* Not already distributed */
and (h.nurse is NULL or h.nurse=00 or h.doctor=00) AND (h.nurse IS NULL OR h.nurse=00 OR h.doctor=00)
/* Has not refused or been aborted */ /* Has not refused or been aborted */
and not (h.status = 'Refused' or h.status = 'Aborted' AND NOT (h.status = 'Refused' OR h.status = 'Aborted'
or h.status = 'Died' or h.status = 'Other') OR h.status = 'Died' OR h.status = 'Other')
order by ORDER BY
tvid; tvid;
@end example @end example
Some explanations: Some explanations:
@table @asis @table @asis
@item @code{concat(p1.id, p1.tvab) + 0 as tvid} @item @code{CONCAT(p1.id, p1.tvab) + 0 AS tvid}
We want to sort on the concatenated @code{id} and @code{tvab} in We want to sort on the concatenated @code{id} and @code{tvab} in
numerical order. Adding @code{0} to the result causes MySQL to numerical order. Adding @code{0} to the result causes MySQL to
treat the result as a number. treat the result as a number.
...@@ -13969,24 +13968,24 @@ event. This indicates in how many pairs both twins are finished, in how many ...@@ -13969,24 +13968,24 @@ event. This indicates in how many pairs both twins are finished, in how many
pairs one twin is finished and the other refused, and so on. pairs one twin is finished and the other refused, and so on.
@example @example
select SELECT
t1.event, t1.event,
t2.event, t2.event,
count(*) COUNT(*)
from FROM
lentus as t1, lentus AS t1,
lentus as t2, lentus AS t2,
twin_project as tp twin_project AS tp
where WHERE
/* We are looking at one pair at a time */ /* We are looking at one pair at a time */
t1.id = tp.id t1.id = tp.id
and t1.tvab=tp.tvab AND t1.tvab=tp.tvab
and t1.id = t2.id AND t1.id = t2.id
/* Just the sceening survey */ /* Just the sceening survey */
and tp.survey_no = 5 AND tp.survey_no = 5
/* This makes each pair only appear once */ /* This makes each pair only appear once */
and t1.tvab='1' and t2.tvab='2' AND t1.tvab='1' AND t2.tvab='2'
group by GROUP BY
t1.event, t2.event; t1.event, t2.event;
@end example @end example
...@@ -17642,14 +17641,14 @@ Some things reported by check table, can't be corrected automatically: ...@@ -17642,14 +17641,14 @@ Some things reported by check table, can't be corrected automatically:
@code{Found row where the auto_increment column has the value 0}. @code{Found row where the auto_increment column has the value 0}.
This means that you have in the table a row where the This means that you have in the table a row where the
@code{auto_increment} index column contains the value 0. @code{AUTO_INCREMENT} index column contains the value 0.
(It's possible to create a row where the auto_increment column is 0 by (It's possible to create a row where the @code{AUTO_INCREMENT} column is 0 by
explicitly setting the column to 0 with an @code{UPDATE} statement) explicitly setting the column to 0 with an @code{UPDATE} statement)
This isn't an error in itself, but could cause trouble if you decide to This isn't an error in itself, but could cause trouble if you decide to
dump the table and restore it or do an @code{ALTER TABLE} on the dump the table and restore it or do an @code{ALTER TABLE} on the
table. In this case the auto_increment column will change value, table. In this case the @code{AUTO_INCREMENT} column will change value,
according to the rules of auto_increment columns, which could cause according to the rules of @code{AUTO_INCREMENT} columns, which could cause
problems like a duplicate key error. problems like a duplicate key error.
To get rid of the warning, just execute an @code{UPDATE} statement To get rid of the warning, just execute an @code{UPDATE} statement
...@@ -18032,8 +18031,8 @@ MySQL. ...@@ -18032,8 +18031,8 @@ MySQL.
@item -d or --description @item -d or --description
Prints some information about table. Prints some information about table.
@item -A or --set-auto-increment[=value] @item -A or --set-auto-increment[=value]
Force auto_increment to start at this or higher value. If no value is Force @code{AUTO_INCREMENT} to start at this or higher value. If no value is
given, then sets the next auto_increment value to the highest used value given, then sets the next @code{AUTO_INCREMENT} value to the highest used value
for the auto key + 1. for the auto key + 1.
@item -S or --sort-index @item -S or --sort-index
Sort the index tree blocks in high-low order. Sort the index tree blocks in high-low order.
...@@ -24386,10 +24385,10 @@ query from the master. ...@@ -24386,10 +24385,10 @@ query from the master.
@item @item
If you have decided you can skip the next query, do If you have decided you can skip the next query, do
@code{SET SQL_SLAVE_SKIP_COUNTER=1; SLAVE START;} to skip a query that @code{SET SQL_SLAVE_SKIP_COUNTER=1; SLAVE START;} to skip a query that
does not use auto_increment, or last_insert_id or does not use @code{AUTO_INCREMENT} or @code{LAST_INSERT_ID()}, or
@code{SET SQL_SLAVE_SKIP_COUNTER=2; SLAVE START;} otherwise. The reason @code{SET SQL_SLAVE_SKIP_COUNTER=2; SLAVE START;} otherwise. The reason
auto_increment/last_insert_id queries are different is that they take queries that use @code{AUTO_INCREMENT} or @code{LAST_INSERT_ID()}
two events in the binary log of the master. are different is that they take two events in the binary log of the master.
@item @item
If you are sure the slave started out perfectly in sync with the master, If you are sure the slave started out perfectly in sync with the master,
...@@ -25928,7 +25927,7 @@ In some cases it may make sense to introduce a column that is 'hashed' ...@@ -25928,7 +25927,7 @@ In some cases it may make sense to introduce a column that is 'hashed'
based on information from other columns. If this column is short and based on information from other columns. If this column is short and
reasonably unique it may be much faster than a big index on many reasonably unique it may be much faster than a big index on many
columns. In MySQL it's very easy to use this extra column: columns. In MySQL it's very easy to use this extra column:
@code{SELECT * FROM table_name WHERE hash=MD5(concat(col1,col2)) @code{SELECT * FROM table_name WHERE hash=MD5(CONCAT(col1,col2))
AND col_1='constant' AND col_2='constant'} AND col_1='constant' AND col_2='constant'}
@item @item
For tables that change a lot you should try to avoid all @code{VARCHAR} For tables that change a lot you should try to avoid all @code{VARCHAR}
...@@ -27302,7 +27301,7 @@ mysql> UPDATE mysql.user SET password=PASSWORD("newpass") ...@@ -27302,7 +27301,7 @@ mysql> UPDATE mysql.user SET password=PASSWORD("newpass")
@item SQL_AUTO_IS_NULL = 0 | 1 @item SQL_AUTO_IS_NULL = 0 | 1
If set to @code{1} (default) then one can find the last inserted row If set to @code{1} (default) then one can find the last inserted row
for a table with an auto_increment row with the following construct: for a table with an @code{AUTO_INCREMENT} column with the following construct:
@code{WHERE auto_increment_column IS NULL}. This is used by some @code{WHERE auto_increment_column IS NULL}. This is used by some
ODBC programs like Access. ODBC programs like Access.
...@@ -29490,7 +29489,7 @@ object. The standard way to do this is with the @code{SUBSTRING} ...@@ -29490,7 +29489,7 @@ object. The standard way to do this is with the @code{SUBSTRING}
function. For example: function. For example:
@example @example
mysql> SELECT comment FROM tbl_name,substring(comment,20) AS substr mysql> SELECT comment FROM tbl_name,SUBSTRING(comment,20) AS substr
-> ORDER BY substr; -> ORDER BY substr;
@end example @end example
...@@ -32612,7 +32611,7 @@ the same @code{INSERT} statement against some other server. ...@@ -32612,7 +32611,7 @@ the same @code{INSERT} statement against some other server.
If @code{expr} is given as an argument to @code{LAST_INSERT_ID()}, then If @code{expr} is given as an argument to @code{LAST_INSERT_ID()}, then
the value of the argument is returned by the function, is set as the the value of the argument is returned by the function, is set as the
next value to be returned by @code{LAST_INSERT_ID()} and used as the next next value to be returned by @code{LAST_INSERT_ID()} and used as the next
auto_increment value. This can be used to simulate sequences: @code{AUTO_INCREMENT} value. This can be used to simulate sequences:
First create the table: First create the table:
...@@ -32729,7 +32728,7 @@ use is in the @code{mysql} client, which reports query execution times: ...@@ -32729,7 +32728,7 @@ use is in the @code{mysql} client, which reports query execution times:
@example @example
mysql> SELECT BENCHMARK(1000000,ENCODE("hello","goodbye")); mysql> SELECT BENCHMARK(1000000,ENCODE("hello","goodbye"));
+----------------------------------------------+ +----------------------------------------------+
| BENCHMARK(1000000,encode("hello","goodbye")) | | BENCHMARK(1000000,ENCODE("hello","goodbye")) |
+----------------------------------------------+ +----------------------------------------------+
| 0 | | 0 |
+----------------------------------------------+ +----------------------------------------------+
...@@ -32909,7 +32908,7 @@ grouping on unnecessary items. For example, you don't need to group on ...@@ -32909,7 +32908,7 @@ grouping on unnecessary items. For example, you don't need to group on
@code{customer.name} in the following query: @code{customer.name} in the following query:
@example @example
mysql> SELECT order.custid,customer.name,max(payments) mysql> SELECT order.custid,customer.name,MAX(payments)
-> FROM order,customer -> FROM order,customer
-> WHERE order.custid = customer.custid -> WHERE order.custid = customer.custid
-> GROUP BY order.custid; -> GROUP BY order.custid;
...@@ -32929,7 +32928,7 @@ column value even if it isn't unique. The following gives the value of ...@@ -32929,7 +32928,7 @@ column value even if it isn't unique. The following gives the value of
column: column:
@example @example
substr(MIN(concat(rpad(sort,6,' '),column)),7) SUBSTR(MIN(CONCAT(RPAD(sort,6,' '),column)),7)
@end example @end example
@xref{example-Maximum-column-group-row}. @xref{example-Maximum-column-group-row}.
...@@ -33119,7 +33118,7 @@ In MySQL Version 3.22.5 or later, you can also write queries like this: ...@@ -33119,7 +33118,7 @@ In MySQL Version 3.22.5 or later, you can also write queries like this:
@example @example
mysql> SELECT user,MAX(salary) FROM users mysql> SELECT user,MAX(salary) FROM users
-> group by user HAVING max(salary)>10; -> GROUP BY user HAVING MAX(salary)>10;
@end example @end example
In older MySQL versions, you can write this instead: In older MySQL versions, you can write this instead:
...@@ -34355,10 +34354,10 @@ For example, to read a file of jokes, that are separated with a line ...@@ -34355,10 +34354,10 @@ For example, to read a file of jokes, that are separated with a line
of @code{%%}, into a SQL table you can do: of @code{%%}, into a SQL table you can do:
@example @example
create table jokes (a int not null auto_increment primary key, joke text CREATE TABLE jokes (a INT NOT NULL AUTO_INCREMENT PRIMARY KEY, joke TEXT
not null); NOT NULL);
load data infile "/tmp/jokes.txt" into table jokes fields terminated by "" LOAD DATA INFILE "/tmp/jokes.txt" INTO TABLE jokes FIELDS TERMINATED BY ""
lines terminated by "\n%%\n" (joke); LINES TERMINATED BY "\n%%\n" (joke);
@end example @end example
@code{FIELDS [OPTIONALLY] ENCLOSED BY} controls quoting of fields. For @code{FIELDS [OPTIONALLY] ENCLOSED BY} controls quoting of fields. For
...@@ -34852,11 +34851,11 @@ with @code{DELETE FROM table_name} (without a @code{WHERE}) in ...@@ -34852,11 +34851,11 @@ with @code{DELETE FROM table_name} (without a @code{WHERE}) in
@strong{NOTE:} There can be only one @code{AUTO_INCREMENT} column per @strong{NOTE:} There can be only one @code{AUTO_INCREMENT} column per
table, and it must be indexed. MySQL Version 3.23 will also only table, and it must be indexed. MySQL Version 3.23 will also only
work properly if the auto_increment column only has positive work properly if the @code{AUTO_INCREMENT} column only has positive
values. Inserting a negative number is regarded as inserting a very large values. Inserting a negative number is regarded as inserting a very large
positive number. This is done to avoid precision problems when positive number. This is done to avoid precision problems when
numbers 'wrap' over from positive to negative and also to ensure that one numbers 'wrap' over from positive to negative and also to ensure that one
doesn't accidentally get an auto_increment column that contains 0. doesn't accidentally get an @code{AUTO_INCREMENT} column that contains 0.
In MyISAM and BDB tables you can specify @code{AUTO_INCREMENT} secondary In MyISAM and BDB tables you can specify @code{AUTO_INCREMENT} secondary
column in a multi-column key. @xref{example-AUTO_INCREMENT}. column in a multi-column key. @xref{example-AUTO_INCREMENT}.
...@@ -34980,7 +34979,7 @@ Only the @code{MyISAM} table type supports indexing on @code{BLOB} and ...@@ -34980,7 +34979,7 @@ Only the @code{MyISAM} table type supports indexing on @code{BLOB} and
@code{TEXT} columns. When putting an index on a @code{BLOB} or @code{TEXT} @code{TEXT} columns. When putting an index on a @code{BLOB} or @code{TEXT}
column you MUST always specify the length of the index: column you MUST always specify the length of the index:
@example @example
CREATE TABLE test (blob_col BLOB, index(blob_col(10))); CREATE TABLE test (blob_col BLOB, INDEX(blob_col(10)));
@end example @end example
@item @item
...@@ -35046,7 +35045,7 @@ The options work for all table types, if not otherwise indicated: ...@@ -35046,7 +35045,7 @@ The options work for all table types, if not otherwise indicated:
@multitable @columnfractions .25 .75 @multitable @columnfractions .25 .75
@item @strong{Option} @tab @strong{Description} @item @strong{Option} @tab @strong{Description}
@item @code{AUTO_INCREMENT} @tab The next auto_increment value you want to set for your table (MyISAM). @item @code{AUTO_INCREMENT} @tab The next @code{AUTO_INCREMENT} value you want to set for your table (MyISAM).
@item @code{AVG_ROW_LENGTH} @tab An approximation of the average row length for your table. You only need to set this for large tables with variable size records. @item @code{AVG_ROW_LENGTH} @tab An approximation of the average row length for your table. You only need to set this for large tables with variable size records.
@item @code{CHECKSUM} @tab Set this to 1 if you want MySQL to maintain a checksum for all rows (makes the table a little slower to update but makes it easier to find corrupted tables) (MyISAM). @item @code{CHECKSUM} @tab Set this to 1 if you want MySQL to maintain a checksum for all rows (makes the table a little slower to update but makes it easier to find corrupted tables) (MyISAM).
@item @code{COMMENT} @tab A 60-character comment for your table. @item @code{COMMENT} @tab A 60-character comment for your table.
...@@ -35689,9 +35688,9 @@ is issued: ...@@ -35689,9 +35688,9 @@ is issued:
@example @example
mysql> USE db1; mysql> USE db1;
mysql> SELECT count(*) FROM mytable; # selects from db1.mytable mysql> SELECT COUNT(*) FROM mytable; # selects from db1.mytable
mysql> USE db2; mysql> USE db2;
mysql> SELECT count(*) FROM mytable; # selects from db2.mytable mysql> SELECT COUNT(*) FROM mytable; # selects from db2.mytable
@end example @end example
Making a particular database current by means of the @code{USE} statement Making a particular database current by means of the @code{USE} statement
...@@ -37233,7 +37232,6 @@ INSERT INTO t2 (message) VALUES ("Testing"),("table"),("t2"); ...@@ -37233,7 +37232,6 @@ INSERT INTO t2 (message) VALUES ("Testing"),("table"),("t2");
CREATE TABLE total (a INT NOT NULL, message CHAR(20), KEY(a)) CREATE TABLE total (a INT NOT NULL, message CHAR(20), KEY(a))
TYPE=MERGE UNION=(t1,t2) INSERT_METHOD=LAST; TYPE=MERGE UNION=(t1,t2) INSERT_METHOD=LAST;
@end example @end example
@c CAPPING DONE TO HERE
Note that we didn't create a @code{UNIQUE} or @code{PRIMARY KEY} in the Note that we didn't create a @code{UNIQUE} or @code{PRIMARY KEY} in the
@code{total} table as the key isn't going to be unique in the @code{total} @code{total} table as the key isn't going to be unique in the @code{total}
...@@ -37251,7 +37249,7 @@ shell> mysqladmin flush-tables ...@@ -37251,7 +37249,7 @@ shell> mysqladmin flush-tables
Now you can do things like: Now you can do things like:
@example @example
mysql> select * from total; mysql> SELECT * FROM total;
+---+---------+ +---+---------+
| a | message | | a | message |
+---+---------+ +---+---------+
...@@ -37384,7 +37382,7 @@ without overflow areas. There is no extra space needed for free lists. ...@@ -37384,7 +37382,7 @@ without overflow areas. There is no extra space needed for free lists.
normally is common with hashed tables: normally is common with hashed tables:
@example @example
mysql> CREATE TABLE test TYPE=HEAP SELECT ip,SUM(downloads) as down mysql> CREATE TABLE test TYPE=HEAP SELECT ip,SUM(downloads) AS down
-> FROM log_table GROUP BY ip; -> FROM log_table GROUP BY ip;
mysql> SELECT COUNT(ip),AVG(down) FROM test; mysql> SELECT COUNT(ip),AVG(down) FROM test;
mysql> DROP TABLE test; mysql> DROP TABLE test;
...@@ -46305,8 +46303,8 @@ You have specified a password in the @code{user} table without using the ...@@ -46305,8 +46303,8 @@ You have specified a password in the @code{user} table without using the
function: function:
@example @example
mysql> update user set password=PASSWORD('your password') mysql> UPDATE user SET password=PASSWORD('your password')
-> where user='XXX'; -> WHERE user='XXX';
@end example @end example
@end itemize @end itemize
...@@ -47116,7 +47114,7 @@ mysql> INSERT INTO tbl_name (idate) VALUES ('0000-00-00'); ...@@ -47116,7 +47114,7 @@ mysql> INSERT INTO tbl_name (idate) VALUES ('0000-00-00');
mysql> SELECT idate FROM tbl_name WHERE idate >= '1997-05-05'; mysql> SELECT idate FROM tbl_name WHERE idate >= '1997-05-05';
mysql> SELECT idate FROM tbl_name WHERE idate >= 19970505; mysql> SELECT idate FROM tbl_name WHERE idate >= 19970505;
mysql> SELECT mod(idate,100) FROM tbl_name WHERE idate >= 19970505; mysql> SELECT MOD(idate,100) FROM tbl_name WHERE idate >= 19970505;
mysql> SELECT idate FROM tbl_name WHERE idate >= '19970505'; mysql> SELECT idate FROM tbl_name WHERE idate >= '19970505';
@end example @end example
...@@ -47565,7 +47563,7 @@ You can't use temporary tables more than once in the same query. ...@@ -47565,7 +47563,7 @@ You can't use temporary tables more than once in the same query.
For example, the following doesn't work. For example, the following doesn't work.
@example @example
select * from temporary_table, temporary_table as t2; mysql> SELECT * FROM temporary_table, temporary_table AS t2;
@end example @end example
We plan to fix the above in 4.0. We plan to fix the above in 4.0.
...@@ -51822,7 +51820,7 @@ Fixed problem when using an @code{AUTO_INCREMENT} column in two keys ...@@ -51822,7 +51820,7 @@ Fixed problem when using an @code{AUTO_INCREMENT} column in two keys
@item @item
With @code{MyISAM}, you now can have an @code{AUTO_INCREMENT} column as a key With @code{MyISAM}, you now can have an @code{AUTO_INCREMENT} column as a key
sub part: sub part:
@code{CREATE TABLE foo (a int not null auto_increment, b char(5), primary key (b,a))} @code{CREATE TABLE foo (a INT NOT NULL AUTO_INCREMENT, b CHAR(5), PRIMARY KEY (b,a))}
@item @item
Fixed bug in @code{MyISAM} with packed char keys that could be @code{NULL}. Fixed bug in @code{MyISAM} with packed char keys that could be @code{NULL}.
@item @item
...@@ -56157,57 +56155,57 @@ characters/constructs: ...@@ -56157,57 +56155,57 @@ characters/constructs:
@item ^ @item ^
Match the beginning of a string. Match the beginning of a string.
@example @example
mysql> select "fo\nfo" REGEXP "^fo$"; -> 0 mysql> SELECT "fo\nfo" REGEXP "^fo$"; -> 0
mysql> select "fofo" REGEXP "^fo"; -> 1 mysql> SELECT "fofo" REGEXP "^fo"; -> 1
@end example @end example
@item $ @item $
Match the end of a string. Match the end of a string.
@example @example
mysql> select "fo\no" REGEXP "^fo\no$"; -> 1 mysql> SELECT "fo\no" REGEXP "^fo\no$"; -> 1
mysql> select "fo\no" REGEXP "^fo$"; -> 0 mysql> SELECT "fo\no" REGEXP "^fo$"; -> 0
@end example @end example
@item . @item .
Match any character (including newline). Match any character (including newline).
@example @example
mysql> select "fofo" REGEXP "^f.*"; -> 1 mysql> SELECT "fofo" REGEXP "^f.*"; -> 1
mysql> select "fo\nfo" REGEXP "^f.*"; -> 1 mysql> SELECT "fo\nfo" REGEXP "^f.*"; -> 1
@end example @end example
@item a* @item a*
Match any sequence of zero or more @code{a} characters. Match any sequence of zero or more @code{a} characters.
@example @example
mysql> select "Ban" REGEXP "^Ba*n"; -> 1 mysql> SELECT "Ban" REGEXP "^Ba*n"; -> 1
mysql> select "Baaan" REGEXP "^Ba*n"; -> 1 mysql> SELECT "Baaan" REGEXP "^Ba*n"; -> 1
mysql> select "Bn" REGEXP "^Ba*n"; -> 1 mysql> SELECT "Bn" REGEXP "^Ba*n"; -> 1
@end example @end example
@item a+ @item a+
Match any sequence of one or more @code{a} characters. Match any sequence of one or more @code{a} characters.
@example @example
mysql> select "Ban" REGEXP "^Ba+n"; -> 1 mysql> SELECT "Ban" REGEXP "^Ba+n"; -> 1
mysql> select "Bn" REGEXP "^Ba+n"; -> 0 mysql> SELECT "Bn" REGEXP "^Ba+n"; -> 0
@end example @end example
@item a? @item a?
Match either zero or one @code{a} character. Match either zero or one @code{a} character.
@example @example
mysql> select "Bn" REGEXP "^Ba?n"; -> 1 mysql> SELECT "Bn" REGEXP "^Ba?n"; -> 1
mysql> select "Ban" REGEXP "^Ba?n"; -> 1 mysql> SELECT "Ban" REGEXP "^Ba?n"; -> 1
mysql> select "Baan" REGEXP "^Ba?n"; -> 0 mysql> SELECT "Baan" REGEXP "^Ba?n"; -> 0
@end example @end example
@item de|abc @item de|abc
Match either of the sequences @code{de} or @code{abc}. Match either of the sequences @code{de} or @code{abc}.
@example @example
mysql> select "pi" REGEXP "pi|apa"; -> 1 mysql> SELECT "pi" REGEXP "pi|apa"; -> 1
mysql> select "axe" REGEXP "pi|apa"; -> 0 mysql> SELECT "axe" REGEXP "pi|apa"; -> 0
mysql> select "apa" REGEXP "pi|apa"; -> 1 mysql> SELECT "apa" REGEXP "pi|apa"; -> 1
mysql> select "apa" REGEXP "^(pi|apa)$"; -> 1 mysql> SELECT "apa" REGEXP "^(pi|apa)$"; -> 1
mysql> select "pi" REGEXP "^(pi|apa)$"; -> 1 mysql> SELECT "pi" REGEXP "^(pi|apa)$"; -> 1
mysql> select "pix" REGEXP "^(pi|apa)$"; -> 0 mysql> SELECT "pix" REGEXP "^(pi|apa)$"; -> 0
@end example @end example
@item (abc)* @item (abc)*
Match zero or more instances of the sequence @code{abc}. Match zero or more instances of the sequence @code{abc}.
@example @example
mysql> select "pi" REGEXP "^(pi)*$"; -> 1 mysql> SELECT "pi" REGEXP "^(pi)*$"; -> 1
mysql> select "pip" REGEXP "^(pi)*$"; -> 0 mysql> SELECT "pip" REGEXP "^(pi)*$"; -> 0
mysql> select "pipi" REGEXP "^(pi)*$"; -> 1 mysql> SELECT "pipi" REGEXP "^(pi)*$"; -> 1
@end example @end example
@item @{1@} @item @{1@}
@itemx @{2,3@} @itemx @{2,3@}
...@@ -56243,12 +56241,12 @@ literal @code{-} character, it must be written first or last. So ...@@ -56243,12 +56241,12 @@ literal @code{-} character, it must be written first or last. So
a defined meaning inside a @code{[]} pair has no special meaning and a defined meaning inside a @code{[]} pair has no special meaning and
matches only itself. matches only itself.
@example @example
mysql> select "aXbc" REGEXP "[a-dXYZ]"; -> 1 mysql> SELECT "aXbc" REGEXP "[a-dXYZ]"; -> 1
mysql> select "aXbc" REGEXP "^[a-dXYZ]$"; -> 0 mysql> SELECT "aXbc" REGEXP "^[a-dXYZ]$"; -> 0
mysql> select "aXbc" REGEXP "^[a-dXYZ]+$"; -> 1 mysql> SELECT "aXbc" REGEXP "^[a-dXYZ]+$"; -> 1
mysql> select "aXbc" REGEXP "^[^a-dXYZ]+$"; -> 0 mysql> SELECT "aXbc" REGEXP "^[^a-dXYZ]+$"; -> 0
mysql> select "gheis" REGEXP "^[^a-dXYZ]+$"; -> 1 mysql> SELECT "gheis" REGEXP "^[^a-dXYZ]+$"; -> 1
mysql> select "gheisa" REGEXP "^[^a-dXYZ]+$"; -> 0 mysql> SELECT "gheisa" REGEXP "^[^a-dXYZ]+$"; -> 0
@end example @end example
@item [[.characters.]] @item [[.characters.]]
The sequence of characters of that collating element. The sequence is a The sequence of characters of that collating element. The sequence is a
...@@ -56284,8 +56282,8 @@ These stand for the character classes defined in the @code{ctype(3)} manual ...@@ -56284,8 +56282,8 @@ These stand for the character classes defined in the @code{ctype(3)} manual
page. A locale may provide others. A character class may not be used as an page. A locale may provide others. A character class may not be used as an
endpoint of a range. endpoint of a range.
@example @example
mysql> select "justalnums" REGEXP "[[:alnum:]]+"; -> 1 mysql> SELECT "justalnums" REGEXP "[[:alnum:]]+"; -> 1
mysql> select "!!" REGEXP "[[:alnum:]]+"; -> 0 mysql> SELECT "!!" REGEXP "[[:alnum:]]+"; -> 0
@end example @end example
@item [[:<:]] @item [[:<:]]
...@@ -56296,13 +56294,13 @@ is neither preceded nor followed by word characters. A word character is ...@@ -56296,13 +56294,13 @@ is neither preceded nor followed by word characters. A word character is
an alnum character (as defined by @code{ctype(3)}) or an underscore an alnum character (as defined by @code{ctype(3)}) or an underscore
(@code{_}). (@code{_}).
@example @example
mysql> select "a word a" REGEXP "[[:<:]]word[[:>:]]"; -> 1 mysql> SELECT "a word a" REGEXP "[[:<:]]word[[:>:]]"; -> 1
mysql> select "a xword a" REGEXP "[[:<:]]word[[:>:]]"; -> 0 mysql> SELECT "a xword a" REGEXP "[[:<:]]word[[:>:]]"; -> 0
@end example @end example
@end table @end table
@example @example
mysql> select "weeknights" REGEXP "^(wee|week)(knights|nights)$"; -> 1 mysql> SELECT "weeknights" REGEXP "^(wee|week)(knights|nights)$"; -> 1
@end example @end example
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