Merge lp:~drizzle-developers/drizzle/major-docs-cleanup into lp:drizzle

Proposed by Henrik Ingo
Status: Merged
Merge reported by: Brian Aker
Merged at revision: not available
Proposed branch: lp:~drizzle-developers/drizzle/major-docs-cleanup
Merge into: lp:drizzle
Diff against target: 2830 lines (+153/-1799)
44 files modified
docs/alter_schema.rst (+1/-6)
docs/alter_table.rst (+1/-13)
docs/commit.rst (+1/-42)
docs/create_index.rst (+1/-12)
docs/create_schema.rst (+4/-3)
docs/create_table.rst (+1/-2)
docs/ddl.rst (+2/-2)
docs/delete.rst (+1/-7)
docs/distinct.rst (+2/-32)
docs/dml.rst (+1/-1)
docs/drop_index.rst (+1/-5)
docs/flush.rst (+6/-6)
docs/functions/aggregatefunctions.rst (+10/-105)
docs/functions/control_flow.rst (+1/-77)
docs/functions/current_time_functions.rst (+1/-78)
docs/functions/date_trunc.rst (+1/-27)
docs/functions/datetime.rst (+3/-36)
docs/functions/extract_date_functions.rst (+1/-150)
docs/functions/logical.rst (+2/-193)
docs/functions/overview.rst (+1/-1)
docs/functions/string.rst (+52/-49)
docs/functions/string/comparative.rst (+6/-47)
docs/functions/string/conversion.rst (+4/-90)
docs/functions/string/length.rst (+3/-18)
docs/functions/string/modification.rst (+1/-114)
docs/functions/string/other.rst (+14/-59)
docs/functions/string/position.rst (+2/-111)
docs/groupby.rst (+2/-78)
docs/having.rst (+2/-58)
docs/insert.rst (+1/-34)
docs/join.rst (+1/-54)
docs/load_data_infile.rst (+1/-36)
docs/orderby.rst (+2/-47)
docs/queries.rst (+3/-12)
docs/rename.rst (+2/-12)
docs/resources/ascii_chart.rst (+1/-100)
docs/savepoints.rst (+3/-3)
docs/start_transaction.rst (+1/-1)
docs/string_data_types.rst (+4/-5)
docs/tables.rst (+1/-11)
docs/transactional.rst (+1/-1)
docs/update.rst (+1/-17)
docs/uuid_data_type.rst (+1/-11)
docs/where.rst (+2/-33)
To merge this branch: bzr merge lp:~drizzle-developers/drizzle/major-docs-cleanup
Reviewer Review Type Date Requested Status
Drizzle Trunk Pending
Review via email: mp+110974@code.launchpad.net

Description of the change

Removing most of what Marisa wrote for the manual, as discussed on Drizzle Day. Marking the missing parts with 'TODO'. Someone else than me needs to rewrite the missing parts. See commit message for details.

Unfortunately we need to push this to trunk (and the published manual) now. Hopefully someone can get some basic content back in soon.

This also needs to be backported to 7.1 and 7.0.

To post a comment you must log in.
Revision history for this message
Brian Aker (brianaker) wrote :

Will it merge with 7.1?

Revision history for this message
Brian Aker (brianaker) wrote :

And it does :)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'docs/alter_schema.rst'
--- docs/alter_schema.rst 2011-11-06 00:00:03 +0000
+++ docs/alter_schema.rst 2012-06-19 08:53:18 +0000
@@ -1,12 +1,7 @@
1ALTER SCHEMA1ALTER SCHEMA
2============2============
33
4ALTER SCHEMA changes the definition of a schema.4'TODO'
5
6You must own the schema to use ALTER SCHEMA. To rename a schema you
7must also have the CREATE privilege for the database. To alter the
8owner, you must also be a direct or indirect member of the new owning
9role, and you must have the CREATE privilege for the database:
105
11.. code-block:: mysql6.. code-block:: mysql
127
138
=== modified file 'docs/alter_table.rst'
--- docs/alter_table.rst 2011-02-13 20:11:55 +0000
+++ docs/alter_table.rst 2012-06-19 08:53:18 +0000
@@ -1,16 +1,4 @@
1ALTER TABLE1ALTER TABLE
2===========2===========
33
4An ALTER statement modifies the definition (structure) of a table inside Drizzle. 4'TODO'
5The types of objects that can be altered depends on which RDBMS is being used.
6
7The ALTER TABLE statement is used to change a table definition by:
8
91) Adding, dropping, modifying table columns
102) Adding and dropping constraints
113) Enabling and Disabling constraints
124) Rename a table
13
14.. todo::
15
16 add something about current implementation: i.e. write blocking copying alter table.
17\ No newline at end of file5\ No newline at end of file
186
=== modified file 'docs/commit.rst'
--- docs/commit.rst 2011-03-08 03:47:42 +0000
+++ docs/commit.rst 2012-06-19 08:53:18 +0000
@@ -3,45 +3,4 @@
33
4COMMIT [WORK] [AND [NO] CHAIN] [[NO] RELEASE]4COMMIT [WORK] [AND [NO] CHAIN] [[NO] RELEASE]
55
6Calling COMMIT will cause the current transaction to save itself.6'TODO'
7
8A COMMIT statement ends a transaction within Drizzle and makes all
9changes visible to other users. The order of events is typically to
10issue a START TRANSACTION statement, execute one or more SQL
11statements, and then issue a COMMIT statement. Alternatively, a
12ROLLBACK statement can be issued, which undoes all the work performed
13since START TRANSACTION was issued. A COMMIT statement will also
14release any existing savepoints that may be in use.
15
16For example, DML statements do not implicitly commit the current
17transaction. If a user's DML statements have been used to update some
18data objects, and the updates need to be permanently recorded in the
19database, you can use the COMMIT command.
20
21An example:
22
23.. code-block:: mysql
24
25 START TRANSACTION;
26
27 INSERT INTO popular_sites (url, id)
28 VALUES ('flickr.com', 07);
29
30 INSERT INTO popular_sites (url, id)
31 VALUES ('twitter.com', 10);
32
33 SELECT * FROM popular_sites;
34
35+-----+---------------+-------+---------------------+
36| id | url | notes | accessed |
37+=====+===============+=======+=====================+
38| 07 | flickr.com | NULL | 2011-02-03 08:33:31 |
39+-----+---------------+-------+---------------------+
40| 10 | twitter.com | NULL | 2011-02-03 08:39:16 |
41+-----+---------------+-------+---------------------+
42
43Then to save the information just inserted, simply issue the COMMIT command:
44
45.. code-block:: mysql
46
47 COMMIT;
48\ No newline at end of file7\ No newline at end of file
498
=== modified file 'docs/create_index.rst'
--- docs/create_index.rst 2011-03-08 03:47:42 +0000
+++ docs/create_index.rst 2012-06-19 08:53:18 +0000
@@ -5,15 +5,4 @@
55
6 CREATE [UNIQUE] INDEX index_name [USING {BTREE | HASH}] ON table_name (column_name [length] [ASC | DESC], ...);6 CREATE [UNIQUE] INDEX index_name [USING {BTREE | HASH}] ON table_name (column_name [length] [ASC | DESC], ...);
77
8An example:8'TODO'
9
10.. code-block:: mysql
11
12 CREATE INDEX table_1_index ON table_1 (a,b);
13
14This would create an index on table_t named table_1_index that converged
15columns a and b.
16
17Fast index creation (where a storage engine can create or drop indexes
18without copying and rebuilding the contents of the entire table) is
19not implemented yet for Drizzle, but it is slated for the future.
20\ No newline at end of file9\ No newline at end of file
2110
=== modified file 'docs/create_schema.rst'
--- docs/create_schema.rst 2011-07-13 02:17:59 +0000
+++ docs/create_schema.rst 2012-06-19 08:53:18 +0000
@@ -1,7 +1,8 @@
1CREATE SCHEMA1CREATE SCHEMA
2==============2==============
33
4CREATE SCHEMA enters a new schema into the current database. The schema name used must be distinct from the name of any existing schema.4TODO
5
56
6.. code-block:: mysql7.. code-block:: mysql
78
@@ -11,7 +12,7 @@
11engine_options12engine_options
12--------------13--------------
1314
14You can specify the storage engine to use for creating the schema. Please note, there is currently only one engine.15TODO
1516
16::17::
1718
@@ -20,7 +21,7 @@
20collate21collate
21-------22-------
2223
23There are default settings for character sets and collations at four levels: server, database, table, and column. The COLLATE clause specifies the default database collation.24TODO
2425
25::26::
2627
2728
=== modified file 'docs/create_table.rst'
--- docs/create_table.rst 2011-07-13 02:17:59 +0000
+++ docs/create_table.rst 2012-06-19 08:53:18 +0000
@@ -1,8 +1,7 @@
1CREATE TABLE1CREATE TABLE
2============2============
33
4A CREATE statement in SQL creates an object inside of Drizzle. One of4'TODO'
5the most common CREATE commands is the CREATE TABLE command.
65
7.. code-block:: mysql6.. code-block:: mysql
87
98
=== modified file 'docs/ddl.rst'
--- docs/ddl.rst 2010-12-04 02:38:29 +0000
+++ docs/ddl.rst 2012-06-19 08:53:18 +0000
@@ -1,7 +1,7 @@
1Data Description Language1Data Definition Language
2=========================2=========================
33
4The Data Definition Language (DDL) is used to define data and their relationships to other data. It is primarily used to create and destroy databases and database objects.4'TODO'
55
6.. toctree::6.. toctree::
7 :maxdepth: 27 :maxdepth: 2
88
=== modified file 'docs/delete.rst'
--- docs/delete.rst 2011-02-23 13:08:09 +0000
+++ docs/delete.rst 2012-06-19 08:53:18 +0000
@@ -1,10 +1,4 @@
1Deleting Data1Deleting Data
2=============2=============
33
4In Drizzle you can make use of DELETE in order to delete a single record (or multiple records) of data from a table.4'TODO'
5
6A typical query might be:
7
8.. code-block:: mysql
9
10 DELETE FROM table_1;
11\ No newline at end of file5\ No newline at end of file
126
=== modified file 'docs/distinct.rst'
--- docs/distinct.rst 2011-10-23 16:01:37 +0000
+++ docs/distinct.rst 2012-06-19 08:53:18 +0000
@@ -1,9 +1,7 @@
1DISTINCT1DISTINCT
2========2========
33
4In a table, columns may contain more than one of the same value. 4'TODO'
5
6Sometimes it's helpful to list only the different, distinct values in a table; in this case the DISTINCT keyword can be used.
75
8SQL SELECT DISTINCT Syntax: 6SQL SELECT DISTINCT Syntax:
97
@@ -12,32 +10,4 @@
12 SELECT DISTINCT column_name(s)10 SELECT DISTINCT column_name(s)
13 FROM table_name11 FROM table_name
1412
15**SELECT DISTINCT Example**13'TODO'
16
17The "Persons" table:
18
19+---------+------------+----------+----------+--------+
20|Id |LastName |FirstName |Address | City |
21+=========+============+==========+==========+========+
22| 1 | Larson | Sue |3 Cherry | Chicago|
23+---------+------------+----------+----------+--------+
24| 2 | Roberts | Teri |21 Brown | Chicago|
25+---------+------------+----------+----------+--------+
26| 3 | Peterson | Kari |30 Mell | Reno |
27+---------+------------+----------+----------+--------+
28
29In order to select distinct values from the column named "City" from the table above, use the following SELECT statement:
30
31.. code-block:: mysql
32
33 SELECT DISTINCT City FROM Persons;
34
35The result-set will look like this:
36
37+--------+
38|City |
39+========+
40|Chicago |
41+--------+
42|Reno |
43+--------+
44\ No newline at end of file14\ No newline at end of file
4515
=== modified file 'docs/dml.rst'
--- docs/dml.rst 2011-03-17 16:33:45 +0000
+++ docs/dml.rst 2012-06-19 08:53:18 +0000
@@ -1,7 +1,7 @@
1Data Manipulation Language1Data Manipulation Language
2==========================2==========================
33
4The Data Manipulation Language (DML) is made up of SQL statements that modify stored data but not the database schema or database objects. Each SQL DML statement is a declarative command, rather than imperative.4'TODO'
55
6.. toctree::6.. toctree::
7 :maxdepth: 27 :maxdepth: 2
88
=== modified file 'docs/drop_index.rst'
--- docs/drop_index.rst 2011-02-23 13:08:09 +0000
+++ docs/drop_index.rst 2012-06-19 08:53:18 +0000
@@ -1,10 +1,6 @@
1DROP INDEX1DROP INDEX
2============2============
33
4This drops a given index on the named table.4'TODO'
5
6.. code-block:: mysql
7
8 DROP INDEX table_1_index ON table_1;
95
10Drizzle does not currently support fast drop index.6Drizzle does not currently support fast drop index.
117
=== modified file 'docs/flush.rst'
--- docs/flush.rst 2011-02-23 14:17:23 +0000
+++ docs/flush.rst 2012-06-19 08:53:18 +0000
@@ -1,7 +1,7 @@
1FLUSH1FLUSH
2=====2=====
33
4The FLUSH statement clears or reloads different internal caches. One variant acquires a lock.4'TODO'
55
6.. code-block:: mysql6.. code-block:: mysql
77
@@ -12,18 +12,18 @@
1212
13* TABLES table_name [, table_name]13* TABLES table_name [, table_name]
14 14
15(closes all specified tables, forces those tables in use to be closed, and flushes the query cache for the named tables)15'TODO'
1616
17* TABLES WITH READ LOCK17* TABLES WITH READ LOCK
18 18
19(closes all open tables and locks all tables for all databases with a global read lock*)19'TODO'
2020
21* LOGS21* LOGS
22 22
23(closes and reopens all log files--if binary logging is enabled, the sequence number of the binary log file is incremented by one relative to the previous file)23'TODO'
2424
25* STATUS25* STATUS
26 26
27(adds the current thread's session status variable values to the global values and resets the session values to zero)27'TODO'
28 28
29To release a FLUSH TABLES WITH READ LOCK, you must issue an UNLOCK TABLES.29'TODO' (how to release a lock)
3030
=== modified file 'docs/functions/aggregatefunctions.rst'
--- docs/functions/aggregatefunctions.rst 2011-02-28 14:09:50 +0000
+++ docs/functions/aggregatefunctions.rst 2012-06-19 08:53:18 +0000
@@ -1,27 +1,20 @@
1Aggregate Functions1Aggregate Functions
2===================2===================
33
4SQL group (aggregate) functions operate on sets of values. If you use an aggregate function in a statement containing no GROUP BY clause, it is equivalent to grouping on all rows.4'TODO'
5
6General syntax for aggregate functions is:
7
8.. code-block:: mysql
9
10 SELECT "function type" ("column_name")
11 FROM "table_name";
125
13The following are examples of aggregate functions:6The following are examples of aggregate functions:
147
15:ref:`avg`: Return the average value of the argument. (Does not work with temporal values unless first converted to numeric values.)8:ref:`avg`: 'TODO'
169
17:ref:`count`10:ref:`count`
18(DISTINCT): Return the count of a number of different values11(DISTINCT): 'TODO'
1912
20:ref:`count`: Return a count of the number of rows returned13:ref:`count`: 'TODO'
21 14
22:ref:`group_concat`: Return a concatenated string15:ref:`group_concat`: 'TODO'
2316
24:ref:`max`: Return the maximum or minim values17:ref:`max`: 'TODO'
2518
2619
27.. _avg:20.. _avg:
@@ -29,113 +22,25 @@
29AVG22AVG
30---23---
3124
32The AVG function returns the average value for the specified column in a table. To find the average session time for users and GROUP BY last_name:25'TODO'
33
34.. code-block:: mysql
35
36 SELECT last_name, AVG(session_length)
37 -> FROM session_details GROUP BY last_name;
38
39AVG() returns NULL if there are no matching rows.
40
4126
42.. _count:27.. _count:
4328
44COUNT29COUNT
45-----30-----
4631
47Take the following "Nodes" table, where 'nodes' are user-contributed content:32'TODO'
48
49+--------+-------------------+------------+----------------+-------------------+
50|NodeID |ContributionDate |NodeSize |NodePopularity |UserName |
51+========+===================+============+================+===================+
52|1 |12/22/2010 |160 |2 |Smith |
53+--------+-------------------+------------+----------------+-------------------+
54|2 |08/10/2010 |190 |2 |Johnson |
55+--------+-------------------+------------+----------------+-------------------+
56|3 |07/13/2010 |500 |5 |Baldwin |
57+--------+-------------------+------------+----------------+-------------------+
58|4 |07/15/2010 |420 |2 |Smith |
59+--------+-------------------+------------+----------------+-------------------+
60|5 |12/22/2010 |1000 |4 |Wood |
61+--------+-------------------+------------+----------------+-------------------+
62|6 |10/2/2010 |820 |4 |Smith |
63+--------+-------------------+------------+----------------+-------------------+
64
65The SQL COUNT function returns the number of rows in a table satisfying the criteria specified in the WHERE clause. If we want to count the number of nodes made by user Smith, we will use the following SQL COUNT expression:
66
67.. code-block:: mysql
68
69 SELECT COUNT * FROM Nodes
70 WHERE UserName = "Smith";
71
72In the above statement, the COUNT keyword returns the number 3, because the user Smith has 3 total nodes.
73
74If you don't specify a WHERE clause when using the COUNT keyword, your statement will simply return the total number of rows in the table, which would be 6 in this example:
75
76.. code-block:: mysql
77
78 SELECT COUNT * FROM Nodes;
79
8033
81.. _group_concat:34.. _group_concat:
8235
83GROUP CONCAT36GROUP CONCAT
84-------------37-------------
8538
86GROUP_CONCAT returns a string result with the concatenated non-NULL values from a group.39'TODO'
87
88For example, without GROUP_CONCAT, this query:
89
90.. code-block:: mysql
91
92 SELECT id,client_id FROM services WHERE id = 3;
93
94Returns:
95
96+----+-----------+
97| id | client_id |
98+====+===========+
99| 3 | 7 |
100+----+-----------+
101| 3 | 8 |
102+----+-----------+
103| 3 | 9 |
104+----+-----------+
105
106But using GROUP_CONCAT in an alternate query:
107
108.. code-block:: mysql
109
110 SELECT id,GROUP_CONCAT(client_id) FROM services WHERE id = 3 GROUP BY id;
111
112Will return:
113
114+----+-------------------------+
115| id | GROUP_CONCAT(client_id) |
116+====+=========================+
117| 3 | 7,8,9 |
118+----+-------------------------+
119
12040
121.. _max:41.. _max:
12242
123MAX and MIN43MAX and MIN
124------------44------------
12545
126MAX returns the maximum value in a group. In cases where MAX is passed a string argument, it will return the maximum string value.46'TODO'
127
128MIN returns the minimum value of a group. Like MAX, MIN returns the minimum string value string value.
129
130MAX and MIN return NULL if there are no matching rows.
131
132.. code-block:: mysql
133
134 SELECT product_id, MIN(price), MAX(price)
135 FROM inventory
136 GROUP BY product_id;
137
138.. note::
139
140 For ``ENUM`` columns :program:`Drizzle` uses the highest and lowest string
141 values for ``MIN`` and ``MAX`` rather than relative position.
142\ No newline at end of file47\ No newline at end of file
14348
=== modified file 'docs/functions/control_flow.rst'
--- docs/functions/control_flow.rst 2011-09-15 13:23:48 +0000
+++ docs/functions/control_flow.rst 2012-06-19 08:53:18 +0000
@@ -1,80 +1,4 @@
1Control Flow Functions1Control Flow Functions
2======================2======================
33
4There are four control flow functions: 4'TODO'
5
6* CASE
7* IF/ELSE
8* IFNULL
9* NULLIF
10
11Control flow functions return a value for each row processed, which represents the result of the comparison or condition specified. They can be used in ``SELECT``, ``WHERE``, ``ORDER BY``, and ``GROUP BY`` statements.
12
13CASE
14----
15
16There are two basic examples of the ``CASE`` statment:
17
18 1. ::
19
20 CASE value WHEN [compare_value] THEN result [WHEN [compare_value] THEN result ...] [ELSE result] END
21
22In this version, result is returned when value is equal to compare_value. If nothing is matched, the result after ``ELSE`` is returned, or ``NULL`` is returned if there is no ``ELSE`` part.
23
24 2. ::
25
26 CASE WHEN [condition] THEN result [WHEN [condition] THEN result ...] [ELSE result] END
27
28In this version, if [condition] is true, result is returned. If nothing is matched, the result after ``ELSE`` is returned, or ``NULL`` is returned if there is no ``ELSE`` part.
29
30When [condition] is for equal comparison (=), this example syntax returns the same result as the first example.
31
32IF/ELSE
33---------
34
35This type of control flow function checks IF a condition is satisfied (i.e. the Boolean expression returns TRUE), the IF SQL statement will execute. IF the condition is not satisfied (i.e. the Boolean expression returns FALSE), the ELSE SQL statement is executed.
36
37Syntax for IF/ELSE: ::
38
39 IF ( Boolean_expression )
40 BEGIN
41 SQL statement
42 END
43 ELSE
44 BEGIN
45 SQL statement
46 END
47
48
49IFNULL
50-------
51
52Given IFNULL(arg1,arg2), if arg1 is not NULL, IFNULL() returns arg1; it otherwise returns arg2. IFNULL() returns a numeric or string value, depending on how it's used.
53
54.. code-block:: mysql
55
56 SELECT IFNULL(2,0);
57 -> 2
58
59 SELECT IFNULL(NULL,1);
60 -> 1
61
62 SELECT IFNULL(1/0,10);
63 -> 10
64
65 SELECT IFNULL(1/0,'yes');
66 -> 'yes'
67
68NULLIF
69-------
70
71NULLIF(arg1,arg2) returns NULL if arg1 = arg2 is true, otherwise returns arg1.
72
73.. code-block:: mysql
74
75 SELECT NULLIF(1,1);
76 -> NULL
77
78 SELECT NULLIF(1,2);
79 -> 1
80
815
=== modified file 'docs/functions/current_time_functions.rst'
--- docs/functions/current_time_functions.rst 2012-03-06 00:19:38 +0000
+++ docs/functions/current_time_functions.rst 2012-06-19 08:53:18 +0000
@@ -1,81 +1,4 @@
1CURRENT TIME FUNCTIONS1CURRENT TIME FUNCTIONS
2=======================2=======================
33
44'TODO'
5current_date
6-------------
7
8Returns the current date as a value in 'YYYY-MM-DD' or YYYYMMDD format, depending on whether the function is used in a string or numeric context.
9
10.. code-block:: mysql
11
12 SELECT CURDATE();
13 -> '2011-02-13'
14 SELECT CURDATE() + 0;
15 -> 20110213
16
17.. _now:
18
19now()
20------
21
22NOW returns the current date and time. The return value will be expressed as 'YYYY-MM-DD HH:MM:SS:mmmmmm' or YYYYMMDDHHMMSS.uuuuuu, depending on whether the function is used in a string or numeric context. The value is expressed in the current time zone (Drizzle timezone is always UTC).
23
24.. code-block:: mysql
25
26 SELECT NOW();
27 -> '2011-02-15 13:40:06:002203'
28 SELECT NOW() + 0;
29 -> 20110215134006.002203
30
31NOW returns a constant time that indicates the time at which the statement began to execute.
32
33.. code-block:: mysql
34
35 SELECT NOW(), SLEEP(2), NOW();
36
37Returns:
38
39+----------------------------+----------+----------------------------+
40| NOW() | SLEEP(2) | NOW() |
41+============================+==========+============================+
42| 2011-02-20 20:15:09:002203 | 0 | 2011-02-20 20:15:09:002203 |
43+----------------------------+----------+----------------------------+
44
45SYSDATE, however, returns the exact time at which the function was invoked.
46
47.. code-block:: mysql
48
49 SELECT SYSDATE(), SLEEP(2), SYSDATE();
50
51Returns:
52
53+---------------------+----------+---------------------+
54| SYSDATE() | SLEEP(2) | SYSDATE() |
55+=====================+==========+=====================+
56| 2011-02-20 20:15:09 | 0 | 2011-02-20 20:15:11 |
57+---------------------+----------+---------------------+
58
59When using replication, the binary log will include SET TIMESTAMP entries so that a database can be restored from the binary log. In doing this, values from NOW will be adjusted to the same times as when the original SQL statements were executed. SYSDATE entries will be unaffected by SET TIMESTAMP entries.
60
61current_timestamp
62------------------
63
64See :ref:`now`
65
66CURRENT_TIMESTAMP() is a synonym for NOW().
67
68localtime
69-----------
70
71See :ref:`now`
72
73LOCALTIME() is a synonym for NOW().
74
75localtimestamp
76---------------
77
78See :ref:`now`
79
80LOCALTIMESTAMP() is a synonym for NOW().
81
82\ No newline at end of file5\ No newline at end of file
836
=== modified file 'docs/functions/date_trunc.rst'
--- docs/functions/date_trunc.rst 2011-03-11 15:54:41 +0000
+++ docs/functions/date_trunc.rst 2012-06-19 08:53:18 +0000
@@ -1,30 +1,4 @@
1DATE TRUNC1DATE TRUNC
2===========2===========
33
4DATE_TRUNC truncates a date to a specified precision. The idea is similar to the trunc function for numbers.4'TODO'
5
6The syntax is: date_trunc(text, source)
7
8Valid values for *text* are:
9
10* microseconds
11* milliseconds
12* second
13* minute
14* hour
15* day
16* week
17* month
18* quarter
19* year
20* decade
21* century
22* millennium
23
24In this example, 'source' is a TIMESTAMP value with microsecond precision:
25
26.. code-block:: mysql
27
28 date_trunc('hour', timestamp '2011-02-26 10:35:44:712005')
29
30Returns: 2011-02-26 10:00:00
31\ No newline at end of file5\ No newline at end of file
326
=== modified file 'docs/functions/datetime.rst'
--- docs/functions/datetime.rst 2012-03-23 21:25:52 +0000
+++ docs/functions/datetime.rst 2012-06-19 08:53:18 +0000
@@ -13,21 +13,7 @@
1313
14For examples of the following, see :doc:`current_time_functions`.14For examples of the following, see :doc:`current_time_functions`.
1515
16+-----------------------------------+-------------------------------------+-----------------------------------------------------------------+16'TODO'
17|Name |Return Type |Description |
18+===================================+=====================================+=================================================================+
19|current_date |date |Current date |
20+-----------------------------------+-------------------------------------+-----------------------------------------------------------------+
21|current_timestamp |timestamp with time zone* |Current date and time (start of current transaction) |
22+-----------------------------------+-------------------------------------+-----------------------------------------------------------------+
23|localtime |time |Current time of day |
24+-----------------------------------+-------------------------------------+-----------------------------------------------------------------+
25|localtimestamp |timestamp |Current date and time (start of current transaction) |
26+-----------------------------------+-------------------------------------+-----------------------------------------------------------------+
27|now() |timestamp with time zone* |Current date and time (start of current transaction) |
28+-----------------------------------+-------------------------------------+-----------------------------------------------------------------+
29|statement_timestamp() |timestamp with time zone* |Current date and time (start of current statement) |
30+-----------------------------------+-------------------------------------+-----------------------------------------------------------------+
3117
32Drizzle timezone is always UTC.18Drizzle timezone is always UTC.
3319
@@ -36,17 +22,7 @@
3622
37For examples of the following, see :doc:`extract_date_functions`.23For examples of the following, see :doc:`extract_date_functions`.
3824
39+--------------------------------+-----------------------+---------------------------------------+25'TODO'
40|Name |Return Type |Description |
41+================================+=======================+=======================================+
42|extract(field from timestamp) |double precision |Get subfield |
43+--------------------------------+-----------------------+---------------------------------------+
44|extract(field from interval) |double precision |Get subfield |
45+--------------------------------+-----------------------+---------------------------------------+
46|date_part(text, timestamp) |double precision |Get subfield (equivalent to extract) |
47+--------------------------------+-----------------------+---------------------------------------+
48|date_part(text, interval) |double precision |Get subfield (equivalent to extract) |
49+--------------------------------+-----------------------+---------------------------------------+
5026
5127
52DATE TRUNC28DATE TRUNC
@@ -54,13 +30,4 @@
5430
55For an example of the following, see :doc:`date_trunc`.31For an example of the following, see :doc:`date_trunc`.
5632
57+--------------------------------+-----------------------+---------------------------------------+33'TODO'
58|Name |Return Type |Description |
59+================================+=======================+=======================================+
60|date_trunc(text, timestamp) |timestamp |Truncate to specified precision |
61+--------------------------------+-----------------------+---------------------------------------+
62
63
64
65
66
67\ No newline at end of file34\ No newline at end of file
6835
=== modified file 'docs/functions/extract_date_functions.rst'
--- docs/functions/extract_date_functions.rst 2011-09-15 18:01:36 +0000
+++ docs/functions/extract_date_functions.rst 2012-06-19 08:53:18 +0000
@@ -8,153 +8,4 @@
88
9 EXTRACT(field FROM source)9 EXTRACT(field FROM source)
1010
11The EXTRACT function retrieves subfields such as day or hour from date/time values. The source value has to be a value expression of type *timestamp*, *time*, *date*, or *interval*. 11'TODO'
12
13*Field* is an identifier or string that identifies the field to extract from the source value. The extract function returns values of type *double precision*.
14
15Examples
16--------
17
18The following field names are available:
19
20day
21^^^
22
23.. code-block:: mysql
24
25 SELECT EXTRACT(DAY FROM TIMESTAMP '2011-02-16 20:38:40');
26
27Day of the month.
28
29*Result: 16*
30
31decade
32^^^^^^
33
34.. code-block:: mysql
35
36 SELECT EXTRACT(DECADE FROM TIMESTAMP '2001-02-16 20:38:40');
37
38The year, divided by 10.
39
40*Result: 200*
41
42dow
43^^^
44
45.. code-block:: mysql
46
47 SELECT EXTRACT(DOW FROM TIMESTAMP '2001-02-16 20:38:40');
48
49The day of the week (Sunday is 0, Saturday is 6)
50
51*Result: 5*
52
53doy
54^^^
55
56.. code-block:: mysql
57
58 SELECT EXTRACT(DOY FROM TIMESTAMP '2001-02-16 20:38:40');
59
60The day of the year (1 - 365/366)
61
62*Result: 47*
63
64hour
65^^^^
66
67.. code-block:: mysql
68
69 SELECT EXTRACT(HOUR FROM TIMESTAMP '2001-02-16 20:38:40');
70
71The hour field (0 - 23)
72
73*Result: 20*
74
75minute
76^^^^^^
77
78.. code-block:: mysql
79
80 SELECT EXTRACT(MINUTE FROM TIMESTAMP '2001-02-16 20:38:40');
81
82The minutes field (0 - 59)
83
84*Result: 38*
85
86month
87^^^^^
88
89For timestamp values, the number of the month within the year (1 - 12).
90For interval values, the number of months (0 - 11).
91
92.. code-block:: mysql
93
94 SELECT EXTRACT(MONTH FROM TIMESTAMP '2010-12-29 08:45:27');
95
96*Result: 12*
97
98.. code-block:: mysql
99
100 SELECT EXTRACT(MONTH FROM INTERVAL '3 years 4 months');
101
102*Result: 4*
103
104.. code-block:: mysql
105
106 SELECT EXTRACT(MONTH FROM INTERVAL '3 years 13 months');
107
108*Result: 1*
109
110quarter
111^^^^^^^
112
113.. code-block:: mysql
114
115 SELECT EXTRACT(QUARTER FROM TIMESTAMP '2010-12-29 08:45:27');
116
117The quarter of the year (1 - 4) containing the date.
118
119*Result: 4*
120
121second
122^^^^^^
123
124.. code-block:: mysql
125
126 SELECT EXTRACT(SECOND FROM TIMESTAMP '2010-12-29 08:45:27');
127
128The seconds field, including fractional parts (0 - 59)
129
130*Result: 27*
131
132timezone
133^^^^^^^^
134
135The time zone offset from UTC, measured in seconds.
136
137week
138^^^^
139
140Returns the week number that a day is in. Weeks are numbered according to ISO 8601:1988.
141
142ISO 8601:1988 means that if the week containing January 1 has four or more days in the new year, then it is week 1; otherwise it is the last week of the previous year, and the next week is week 1. The ISO-8601 week starts on Monday.
143
144It's possible for early January dates to be part of the 52nd or 53rd week of the previous year. For example, 2011-01-01 was part of the 52nd week of year 2010.
145
146.. code-block:: mysql
147
148 SELECT EXTRACT(WEEK FROM TIMESTAMP '2010-01-25 12:44:06');
149
150*Result: 4*
151
152year
153^^^^
154
155.. code-block:: mysql
156
157 SELECT EXTRACT(YEAR FROM TIMESTAMP '2009-02-16 20:38:40');
158
159*Result: 2009*
160
161\ No newline at end of file12\ No newline at end of file
16213
=== modified file 'docs/functions/logical.rst'
--- docs/functions/logical.rst 2011-02-23 13:08:09 +0000
+++ docs/functions/logical.rst 2012-06-19 08:53:18 +0000
@@ -17,167 +17,28 @@
17============================== ================================17============================== ================================
1818
1919
20'TODO'
21
20.. _and:22.. _and:
2123
22AND24AND
23---25---
2426
25This logical operator AND:
26
27* evaluates to 1 if all operands are nonzero and not NULL
28* evaluates to 0 if one or more operands are 0
29* otherwise returns NULL
30
31.. code-block:: mysql
32
33 SELECT 1 && 1;
34 -> 1
35 SELECT 1 && 0;
36 -> 0
37 SELECT 1 && NULL;
38 -> NULL
39 SELECT 0 && NULL;
40 -> 0
41 SELECT NULL && 0;
42 -> 0
43
44AND can be used to select rows that satisfy all the conditions given in a statement. For Example, to find the names of the students between the age 20 to 25 years, the query would be like:
45
46.. code-block:: mysql
47
48 SELECT first_name, last_name, age
49 FROM user_details
50 WHERE age >= 20 AND age <= 25;
51
52The output would be:
53
54+---------------+------------------+-------+
55|first_name |last_name |age |
56+===============+==================+=======+
57|Mary |Bean |20 |
58+---------------+------------------+-------+
59|Henry |Catson |22 |
60+---------------+------------------+-------+
61|Sheila |Donaldson |25 |
62+---------------+------------------+-------+
63
64The logical "AND" operator selects rows only if the data in all relevant columns is satisfied. In this case, 'first_name' and 'last_name' simply need to have non-NULL values, and 'age' needs to be a value between 20 and 25.
65
66.. _or:27.. _or:
6728
68OR29OR
69--30--
7031
71This logical operator OR:
72
73* returns 1 if any operand is nonzero and both operands are non-NULL, and returns 0 otherwise
74* returns 1 with a NULL operand if the other operand is nonzero, and retunes NULL otherwise
75* returns NULL if both operands are NULL
76
77.. code-block:: mysql
78
79 SELECT 1 || 1;
80 -> 1
81 SELECT 1 || 0;
82 -> 1
83 SELECT 0 || 0;
84 -> 0
85 SELECT 1 || NULL;
86 -> 1
87 SELECT 0 || NULL;
88 -> NULL
89
90In other words, OR is used to select rows that satisfy at least one of the given conditions.
91
92For example, the following query could be used to find the user_id for people that live in either California or Texas:
93
94.. code-block:: mysql
95
96 SELECT user_id, state
97 FROM user_location
98 WHERE state = 'California' OR state = 'Texas';
99
100The result set could be something like:
101
102+---------------+------------------+-----------+
103|user_id |city |state |
104+===============+==================+===========+
105|608 |Sacremento |California |
106+---------------+------------------+-----------+
107|844 |Austin |Texas |
108+---------------+------------------+-----------+
109|917 |Oakland |California |
110+---------------+------------------+-----------+
111
112
113.. _xor:32.. _xor:
11433
115XOR34XOR
116---35---
11736
118* returns NULL if either operand is NULL
119* evaluates to 1 for non-NULL operands (if an odd number of operands is nonzero)
120* otherwise 0 is returned
121
122.. code-block:: mysql
123
124 SELECT 1 XOR NULL;
125 -> NULL
126 SELECT 1 XOR 0;
127 -> 1
128 SELECT 1 XOR 1 XOR 1;
129 -> 1
130 SELECT 1 XOR 1;
131 -> 0
132
133Note that "a XOR b" is the mathematical equivalent of (a AND (NOT b)) OR ((NOT a) and b).
134
135
136.. _not:37.. _not:
13738
138NOT39NOT
139---40---
14041
141This logical operator NOT:
142
143* evaluates to 1 if the operand is 0
144* evaluates to 0 if the operand is nonzero
145* NOT NULL returns NULL
146
147.. code-block:: mysql
148
149 SELECT NOT 10;
150 -> 0
151 SELECT NOT 0;
152 -> 1
153 SELECT NOT NULL;
154 -> NULL
155 SELECT ! (1+1);
156 -> 0
157 SELECT ! 1+1;
158 -> 1
159
160If you want to find rows that do not satisfy a condition, you can use the logical operator, NOT. NOT results in the reverse of a condition. That is, if a condition is satisfied, then the row is not returned.
161
162For example: If you want to find out the user_id for people who do not practice medicine as their profession, the query would be like:
163
164.. code-block:: mysql
165
166 SELECT user_id, title, occupation
167 FROM user_occupations
168 WHERE NOT occupation = 'Doctor';
169
170The result set would be something like:
171
172+---------------+------------------+--------------+
173|user_id |degree |occupation |
174+===============+==================+==============+
175|322 |PhD |Professor |
176+---------------+------------------+--------------+
177|579 |PhD |Writer |
178+---------------+------------------+--------------+
179|681 |MD |Consultant |
180+---------------+------------------+--------------+
18142
18243
183.. _less_than:44.. _less_than:
@@ -185,12 +46,6 @@
185LESS THAN46LESS THAN
186----------47----------
18748
188Less than:
189
190.. code-block:: mysql
191
192 SELECT 2 < 2;
193 -> 0
19449
19550
196.. _greater_than:51.. _greater_than:
@@ -198,72 +53,26 @@
198GREATER THAN53GREATER THAN
199-------------54-------------
20055
201Greater than:
202
203.. code-block:: mysql
204
205 SELECT 2 > 2;
206 -> 0
20756
208.. _less_or_equal:57.. _less_or_equal:
20958
210LESS THAN OR EQUAL59LESS THAN OR EQUAL
211-------------------60-------------------
21261
213Less than or equal:
214
215.. code-block:: mysql
216
217 SELECT 0.1 <= 2;
218 -> 1
219
22062
221.. _greater_or_equal:63.. _greater_or_equal:
22264
223GREATER THAN OR EQUAL65GREATER THAN OR EQUAL
224----------------------66----------------------
22567
226Greater than or equal:
227
228.. code-block:: mysql
229
230 SELECT 2 >= 2;
231 -> 1
232
233.. _equal:68.. _equal:
23469
235EQUAL70EQUAL
236-----71-----
23772
238Equal:
239
240.. code-block:: mysql
241
242 SELECT 1 = 0;
243 -> 0
244 SELECT '0' = 0;
245 -> 1
246 SELECT '0.0' = 0;
247 -> 1
248 SELECT '0.01' = 0;
249 -> 0
250 SELECT '.01' = 0.01;
251 -> 1
252
25373
254.. _not_equal:74.. _not_equal:
25575
256NOT EQUAL76NOT EQUAL
257----------77----------
25878
259Not equal:
260
261.. code-block:: mysql
262
263 SELECT '.01' <> '0.01';
264 -> 1
265 SELECT .01 <> '0.01';
266 -> 0
267 SELECT 'zing' <> 'zingg';
268 -> 1
269
27079
=== modified file 'docs/functions/overview.rst'
--- docs/functions/overview.rst 2011-08-13 20:41:38 +0000
+++ docs/functions/overview.rst 2012-06-19 08:53:18 +0000
@@ -1,7 +1,7 @@
1SQL Functions1SQL Functions
2=============2=============
33
4Several SQL functions are built into Drizzle--functions perform calculations on data. They can be be understood in categories: 4'TODO'
5 5
6.. toctree::6.. toctree::
7 :maxdepth: 27 :maxdepth: 2
88
=== modified file 'docs/functions/string.rst'
--- docs/functions/string.rst 2011-08-13 20:41:38 +0000
+++ docs/functions/string.rst 2012-06-19 08:53:18 +0000
@@ -18,18 +18,21 @@
18Summary of Functions18Summary of Functions
19--------------------19--------------------
2020
21'TODO' descriptions
22'TODO' "regular functions" ...there are no regular or irregular functions!!!
23
21Comparative and regular functions24Comparative and regular functions
22^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^25^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2326
24=================== ====================================================================================================27=================== ====================================================================================================
25Operator Description28Operator Description
26=================== ==================================================================================================== 29=================== ====================================================================================================
27LIKE Matches a simple pattern30LIKE
28NOT LIKE Negation of simple pattern matching31NOT LIKE
29STRCMP() Compare two strings32STRCMP()
30NOT REGEXP Negation of REGEXP33NOT REGEXP
31REGEXP Returns values that match a regular expression pattern34REGEXP
32RLIKE Synonym for REGEXP35RLIKE
33=================== ====================================================================================================36=================== ====================================================================================================
3437
3538
@@ -38,15 +41,15 @@
38=================== ====================================================================================================41=================== ====================================================================================================
39Operator Description42Operator Description
40=================== ====================================================================================================43=================== ====================================================================================================
41ASCII() Return numeric value of left-most character44ASCII()
42BIN() Return a string representation of the argument45BIN()
43CHAR() Return the character for each integer passed46CHAR()
44HEX() Return a hexadecimal representation of a decimal or string value47HEX()
45LOWER() Return the argument in lowercase48LOWER()
46LCASE() Synonym for LOWER()49LCASE()
47UCASE() Synonym for UPPER()50UCASE()
48UNHEX() Convert each pair of hexadecimal digits to a character51UNHEX()
49UPPER() Convert to uppercase52UPPER()
50=================== ====================================================================================================53=================== ====================================================================================================
5154
5255
@@ -55,10 +58,10 @@
55=================== ====================================================================================================58=================== ====================================================================================================
56Operator Description59Operator Description
57=================== ====================================================================================================60=================== ====================================================================================================
58BIT_LENGTH() Return length of argument in bits61BIT_LENGTH()
59CHAR_LENGTH() Return number of characters in argument62CHAR_LENGTH()
60LENGTH() Return the length of a string in bytes63LENGTH()
61OCTET_LENGTH() A synonym for LENGTH()64OCTET_LENGTH()
62=================== ====================================================================================================65=================== ====================================================================================================
6366
6467
@@ -67,10 +70,10 @@
67=================== ====================================================================================================70=================== ====================================================================================================
68Operator Description71Operator Description
69=================== ====================================================================================================72=================== ====================================================================================================
70CONCAT() Returns a concatenated string73CONCAT()
71TRIM() Remove leading and trailing spaces74TRIM()
72LTRIM() Remove leading spaces75LTRIM()
73RTRIM() Remove trailing spaces76RTRIM()
74=================== ====================================================================================================77=================== ====================================================================================================
7578
7679
@@ -80,13 +83,13 @@
80=================== ====================================================================================================83=================== ====================================================================================================
81Operator Description84Operator Description
82=================== ==================================================================================================== 85=================== ====================================================================================================
83FIELD() Return the index (position) of the first argument in the sequent arguments86FIELD()
84FIND_IN_SET() Return the index position of the first argument within the second argument87FIND_IN_SET()
85INSTR() Return the index of the first occurrence of substring88INSTR()
86LEFT() Return the leftmost number of characters as specified89LEFT()
87INSERT() Insert a substring at the specified position up to the specified number of characters90INSERT()
88LOCATE() Return the position of the first occurrence of substring91LOCATE()
89POSITION() A synonym for LOCATE()92POSITION()
90=================== ==================================================================================================== 93=================== ====================================================================================================
9194
9295
@@ -96,24 +99,24 @@
96=================== ====================================================================================================99=================== ====================================================================================================
97Operator Description100Operator Description
98=================== ==================================================================================================== 101=================== ====================================================================================================
99ELT() Return string at index number102ELT()
100EXPORT_SET() Return a string103EXPORT_SET()
101FORMAT() Return a number formatted to specified number of decimal places104FORMAT()
102LOAD_FILE() Load the named file105LOAD_FILE()
103LPAD() Return the string argument, left-padded with the specified string106LPAD()
104MAKE_SET() Return a set of comma-separated strings that have the corresponding bit in bits set107MAKE_SET()
105MATCH Perform full-text search108MATCH
106MID() Return a substring starting from the specified position109MID()
107ORD() Return character code for leftmost character of the argument110ORD()
108QUOTE() Escape the argument for use in an SQL statement111QUOTE()
109REPEAT() Repeat a string the specified number of times112REPEAT()
110REPLACE() Replace occurrences of a specified string113REPLACE()
111REVERSE() Reverse the characters in a string114REVERSE()
112RIGHT() Return the specified rightmost number of characters115RIGHT()
113RPAD() Append string the specified number of times116RPAD()
114SOUNDEX() Return a soundex string117SOUNDEX()
115SUBSTR() Return the substring as specified118SUBSTR()
116SUBSTRING_INDEX() Return a substring from a string before the specified number of occurrences of the delimiter119SUBSTRING_INDEX()
117SUBSTRING() Return the substring as specified120SUBSTRING()
118=================== ====================================================================================================121=================== ====================================================================================================
119122
120123
=== modified file 'docs/functions/string/comparative.rst'
--- docs/functions/string/comparative.rst 2011-08-13 20:41:38 +0000
+++ docs/functions/string/comparative.rst 2012-06-19 08:53:18 +0000
@@ -1,72 +1,31 @@
1Comparative Functions1Comparative Functions
2=====================2=====================
33
4'TODO'
5
4.. _like-function:6.. _like-function:
57
6LIKE 8LIKE
7----9----
810
9The LIKE operator is used to check if field values match a specified pattern, and searches for less-than-exact but similar values.11
1012
11The LIKE operator supports the use of two wildcards. (Wildcards provide more flexibility by allowing any character or group of characters in a string to be acceptable as a match for another string):
12
13 * Percentage (%): Represents zero or more values.
14 * Underscore (_): Matches exactly one character value.
15
16In accordance the SQL standard, LIKE performs matching on a per-character basis. It therefore provides results different from the = comparison operator.
17
18The following SELECT statement includes a WHERE clause in order to search for job titles that start with "DIRECTOR", by using the percentage wildcard after the lookup value.
19
20For example:
21
22.. code-block:: mysql
23
24 SELECT title, field
25 FROM job_detail
26 WHERE title LIKE 'DIRECTOR%'
27 ORDER BY field, title;
2813
29.. _regex-function:14.. _regex-function:
3015
31REGEX16REGEX
32-----17-----
3318
34Undocumented.
3519
36.. _regexp-function:20.. _regexp-function:
3721
38REGEXP22REGEXP
39------23------
4024
41Returns values that match a regular expression pattern; they are commonly used for creating complex searches. Here is an example of using a REGEXP (Regular Expression) match:25
42
43.. code-block:: mysql
44
45 SELECT title, category_name
46 FROM film_detail
47 WHERE title REGEXP '^AIRP[LO]'
48 ORDER BY title;
49
50Other REGEXP examples:
51
52.. code-block:: mysql
53
54 SELECT 'abcabc' REGEXP 'abc',
55 'abcabc' REGEXP 'cb';
56
57The search pattern may describe only a part of string. To match entire string, use ^ and $ in the search:
58
59.. code-block:: mysql
60
61 SELECT 'abc' REGEXP '^abc$', 'abcabc' REGEXP '^abc$';
62
63 SELECT 'cde' REGEXP '[a-c]+', 'efg' REGEXP '[a-c]+';
64
65 SELECT 'abcabc' REGEXP 'ABC', 'abcabc' REGEXP BINARY 'ABC';
6626
67.. _strcmp-function:27.. _strcmp-function:
6828
69STRCMP29STRCMP
70------30------
7131
72The purpose of STRCMP is also to compare two strings. This function returns 0 if two strings are the same, -1 if the first argument is smaller than the second according to the current sort order, and 1 otherwise.
7332
=== modified file 'docs/functions/string/conversion.rst'
--- docs/functions/string/conversion.rst 2011-08-13 20:41:38 +0000
+++ docs/functions/string/conversion.rst 2012-06-19 08:53:18 +0000
@@ -1,145 +1,59 @@
1Conversion Functions1Conversion Functions
2====================2====================
33
4'TODO'
5
4.. _ascii-function:6.. _ascii-function:
57
6ASCII8ASCII
7-----9-----
810
9The ASCII(str) function returns the numeric value of the leftmost character of the string ’str’. It returns NULL if str is NULL. It works for 8-bit characters.
10
11For example:
12
13.. code-block:: mysql
14
15 SELECT ASCII('0');
16
17Returns 48
18
19.. code-block:: mysql
20
21 SELECT ASCII('d');
22
23Returns 100
2411
25.. _bin-function:12.. _bin-function:
2613
27BIN14BIN
28---15---
2916
30The BIN string function returns a string value that represents the binary value of N, where N is a longlong(BIGINT) number. This function is equivalent to CONV(N, 10 , 0). If the function return the null then N is null.
31
32Syntax:
33
34BIN (N);
35
36For exempt:
37
38.. code-block:: mysql
39
40 SELECT BIN(12);
41
42Returns: '1100'
43
44
45.. _char-function:17.. _char-function:
4618
47CHAR19CHAR
48----20----
4921
50SQL CHAR function is the opposite of the ASCII function. It converts an integer in range 0-255 into a ASCII character. It returns a string (the character), given the integer value. This function skips NULL values.   
5122
52For example:
53
54.. code-block:: mysql
55
56 SELECT CHAR(65) AS ch_65;
57
58Returns "A"
5923
6024
61.. _hex-function:25.. _hex-function:
6226
63HEX27HEX
64---28---
6529
66This string function returns the hexadecimal (base-16) representation of a string or decicmal argument. Each character in the string argument is converted to two hexadecimal digits. If the argument is numeric, HEX() returns a hexadecimal string representation of the value as a BIGINT number.
67
68Using HEX for numeric values:
69
70.. code-block:: mysql
71
72 SELECT HEX(255);
73
74Returns: FF
75
76Using HEX for string values:
77
78.. code-block:: mysql
79
80 SELECT HEX('Drizzle');
81
82Returns: 4452495A5AHc45
83
84(To better understand this output, you can use an :doc:`../../resources/ascii_chart` that includes both Hexadecimal and character values.)
8530
86.. _unhex-function:31.. _unhex-function:
8732
88UNHEX33UNHEX
89-----34-----
9035
91UNHEX converts each pair of hexadecimal digits to a character. For a string argument, UNHEX() is the inverse operation of HEX(str).36
92
93Instead of converting each character in the string argument to hex digits, it interprets each pair of characters in the argument as a hexadecimal number and converts it to the character represented by the number. The return value is a binary string.
94
95.. code-block:: mysql
96
97 SELECT UNHEX('4452495A5AHc45');
98
99Returns 'drizzle'
100
101.. code-block:: mysql
102
103 SELECT UNHEX(HEX('string'));
104
105Returns 'string'
106
107.. code-block:: mysql
108
109 SELECT HEX(UNHEX('1267'));
110
111Returns '1267'
112
113The characters in the argument string must be legal hexadecimal digits: '0' .. '9', 'A' .. 'F', 'a' .. 'f'. If the argument contains any non-hexadecimal digits, the result is NULL:
114
115.. code-block:: mysql
116
117 SELECT UNHEX('GG');
118
119Returns NULL
12037
121.. _lower-function:38.. _lower-function:
12239
123LOWER40LOWER
124-----41-----
12542
126Return the argument in lowercase.
12743
128.. _lcase-function:44.. _lcase-function:
12945
130LCASE46LCASE
131-----47-----
13248
133Synonym for LOWER().
13449
135.. _ucase-function:50.. _ucase-function:
13651
137UCASE52UCASE
138-----53-----
13954
140Synonym for UPPER()
14155
142.. _upper-function:56.. _upper-function:
14357
144UPPER58UPPER
145-----59-----
14660
147Convert to uppercase.61
14862
=== modified file 'docs/functions/string/length.rst'
--- docs/functions/string/length.rst 2011-09-15 13:23:48 +0000
+++ docs/functions/string/length.rst 2012-06-19 08:53:18 +0000
@@ -1,43 +1,28 @@
1Length and Size Functions1Length and Size Functions
2=========================2=========================
33
4'TODO'
5
4.. _char-length-function:6.. _char-length-function:
57
6CHAR_LENGTH8CHAR_LENGTH
7-----------9-----------
8The CHAR_LENGTH(str) function returns string length measured in characters. 10
9
10A multi-byte character counts as single character such as a string contains 5 two-byte characters, then LENGTH() function returns 10, but the CHAR_LENGTH() returns 5. ::
11
12 CHARACTER_LENGTH(str)
13
14This function is same as CHAR_LENGTH().
1511
16.. _character-length-function:12.. _character-length-function:
1713
18CHARACTER_LENGTH14CHARACTER_LENGTH
19----------------15----------------
2016
21Synonym for CHAR_LENGTH.
2217
23.. _length-function:18.. _length-function:
2419
25LENGTH20LENGTH
26------21------
2722
28The LENGTH function returns the length of the string argument in bytes. A multi-byte character counts as multiple bytes. This means that for a string containing a three-byte character, LENGTH() returns 3, whereas CHAR_LENGTH() returns 1. For example:
29
30.. code-block:: mysql
31
32 select length('€');
33
34Returns 3
35
36The is because the Euro sign is encoded as 0xE282AC in UTF-8 and thereby occupies 3 bytes.
3723
38.. _octet-length-function:24.. _octet-length-function:
3925
40OCTET_LENGTH26OCTET_LENGTH
41-------------27-------------
4228
43A synonym for LENGTH().
4429
=== modified file 'docs/functions/string/modification.rst'
--- docs/functions/string/modification.rst 2011-09-15 13:44:31 +0000
+++ docs/functions/string/modification.rst 2012-06-19 08:53:18 +0000
@@ -1,117 +1,4 @@
1String Modification Functions1String Modification Functions
2=============================2=============================
33
4.. _concat-function:4'TODO'
5
6CONCAT
7------
8
9The SQL standard defines a concatenation operator ( || ), which joins two or more strings into one string value.
10The CONCAT(str1, str2...) function can have one or more arguments. It returns a string that is the result of concatenating the arguments.
11
12* If arguments are non-binary strings, the result is also a non-binary string.
13* If any argument is a binary string, then the result will also be a binary string.
14* Numeric arguments are converted to their equivalent in binary string format.
15* If any argument is NULL then it also returns NULL.
16
17Syntax:
18
19CONCAT(str1, str2, [,...n])
20For example:
21
22.. code-block:: mysql
23
24 SELECT CONCAT('Dr', 'izzl', 'ed');
25
26Returns: 'Drizzled'
27
28.. code-block:: mysql
29
30 SELECT CONCAT('micro', NULL, 'nel');
31
32Returns: NULL
33
34.. code-block:: mysql
35
36 SELECT CONCAT(14.8);
37
38Returns: '14.8'
39
40.. _concat-ws-function:
41
42CONCAT_WS
43---------
44CONCAT WS (With Separator) [1]_ allows you to specify that the first argument is treated as a separator for the rest of the arguments. This argument is added between the strings to be concatenated.
45
46Syntax:
47
48CONCAT_WS(separator, str1, str2,....)
49
50For example:
51
52.. code-block:: mysql
53
54 SELECT CONCAT_WS(',', ' Occupation', 'First name', 'Last Name');
55
56Returns: 'Occupation, First name, Last Name'
57
58.. code-block:: mysql
59
60 SELECT CONCAT_WS(',', 'First name', NULL, 'Last Name');
61
62Returns: 'First name, Last Name'
63
64.. _trim-function:
65
66TRIM
67----
68
69The TRIM function remove specified prefixes or suffixes from a string (typically leading and trailing spaces), and returns the resulting string. If none of the specifiers BOTH, LEADING, or TRAILING is given, BOTH is assumed.
70
71Syntax:
72
73TRIM([{BOTH | LEADING | TRAILING} [remstr] FROM] str), TRIM([remstr FROM] str)
74
75[remstr] is optional (if it's not specified, spaces are removed).
76
77For example:
78
79.. code-block:: mysql
80
81 SELECT TRIM(BOTH 'hello,' FROM 'hello,Drizzlehello,');
82
83Returns: 'Drizzle'
84
85.. _ltrim-function:
86
87LTRIM
88-----
89
90This version of the TRIM function removes leading spaces from the beginning of a string.
91
92For example:
93
94.. code-block:: mysql
95
96 SELECT LTRIM(' Drizzle');
97
98Returns: 'Drizzle'
99
100.. _rtrim-function:
101
102RTRIM
103-----
104
105This version of the TRIM function removes trailing spaces from the end of a function.
106
107For example:
108
109.. code-block:: mysql
110
111 SELECT RTRIM('Drizzle ');
112
113Returns: 'Drizzle'
114
115.. rubric:: Footnotes
116
117.. [1] If the separator is NULL then the result is NULL.
118\ No newline at end of file5\ No newline at end of file
1196
=== modified file 'docs/functions/string/other.rst'
--- docs/functions/string/other.rst 2011-09-15 13:58:14 +0000
+++ docs/functions/string/other.rst 2012-06-19 08:53:18 +0000
@@ -1,171 +1,126 @@
1Other String Functions1Other String Functions
2======================2======================
33
4'TODO'
5
4.. _coercibility-function:6.. _coercibility-function:
57
6COERCIBILITY8COERCIBILITY
7------------9------------
810
9Gets coercibility for an expression.11
1012
11.. _elt-function:13.. _elt-function:
1214
13ELT15ELT
14---16---
1517
16Return string at index number.
1718
18.. _export-set-function:19.. _export-set-function:
1920
20EXPORT_SET21EXPORT_SET
21----------22----------
2223
23Return a string
2424
25.. _format-function:25.. _format-function:
2626
27FORMAT27FORMAT
28------28------
2929
30Return a number formatted to specified number of decimal places.
3130
32.. _load-file-function:31.. _load-file-function:
3332
34LOAD_FILE33LOAD_FILE
35---------34---------
3635
37Load the named file.
3836
39.. _lpad-function:37.. _lpad-function:
4038
41LPAD39LPAD
42----40----
4341
44Return the string argument, left-padded with the specified string.
4542
46.. _make-set-function:43.. _make-set-function:
4744
48MAKE_SET45MAKE_SET
49--------46--------
5047
51Return a set of comma-separated strings that have the corresponding bit in bits set.48
5249
53.. _match-function:50.. _match-function:
5451
55MATCH52MATCH
56-----53-----
5754
58Perform full-text search.
5955
60.. _mid-function:56.. _mid-function:
6157
62MID58MID
63---59---
6460
65Return a substring starting from the specified position.
6661
67.. _quote-function:62.. _quote-function:
6863
69QUOTE64QUOTE
70-----65-----
7166
72Escape the argument for use in an SQL statement.
7367
74.. _repeat-function:68.. _repeat-function:
7569
76REPEAT70REPEAT
77------71------
7872
79Repeat a string the specified number of times.
8073
81.. _replace-function:74.. _replace-function:
8275
83REPLACE76REPLACE
84-------77-------
8578
86The REPLACE() function returns a string with all occurrences of the 'from_str' replaced by 'to_str'. REPLACE is case-sensitive when searching for 'from_str'.79
87
88Syntax:
89
90REPLACE(str,from_str,to_str)
91
92For example:
93
94.. code-block:: mysql
95
96 SELECT REPLACE('www.google.com', 'w', 'v');
97
98Returns: vvv.google.com
9980
100.. _reverse-function:81.. _reverse-function:
10182
102REVERSE83REVERSE
103-------84-------
10485
105This function returns a string argument with the characters in reverse order.86
10687
107.. code-block:: mysql
108
109 SELECT REVERSE('abcd');
110
111Returns: dcba
11288
113.. _right-function:89.. _right-function:
11490
115RIGHT91RIGHT
116-----92-----
11793
118Return the specified rightmost number of characters94
11995
120.. _rpad-function:96.. _rpad-function:
12197
122RPAD98RPAD
123----99----
124100
125Append string the specified number of times101
102
126103
127.. _soundex-function:104.. _soundex-function:
128105
129SOUNDEX106SOUNDEX
130-------107-------
131108
132Return a soundex string109
110
133111
134.. _substr-function:112.. _substr-function:
135113
136SUBSTR114SUBSTR
137------115------
138116
139Synonym for SUBSTRING().117
140118
141.. _substring-function:119.. _substring-function:
142120
143SUBSTRING121SUBSTRING
144---------122---------
145123
146Returns the substring as specified
147
148Examples that use SUBSTRING() in the SELECT clause:
149
150The SUBSTRING() function is used to extract a character string (using a given starting position and a given length).
151
152.. code-block:: mysql
153
154 SELECT
155 SUBSTRING(course_designater,6,3) as 'Course number'
156 FROM Courses
157 WHERE course_designater LIKE 'Excel%'
158 LIMIT 10;
159
160You can also format a column using SUBSTRING() in combination with functions like LOWER() and UPPER().
161
162.. code-block:: mysql
163
164 SELECT
165 CONCAT(UPPER(SUBSTRING(lastname,1,1)),
166 LOWER(SUBSTRING(lastname,2,29)))
167 FROM Students
168 LIMIT 10;
169124
170.. _substring-index-function:125.. _substring-index-function:
171126
@@ -173,4 +128,4 @@
173SUBSTRING_INDEX128SUBSTRING_INDEX
174---------------129---------------
175130
176Return a substring from a string before the specified number of occurrences of the delimiter.131
177132
=== modified file 'docs/functions/string/position.rst'
--- docs/functions/string/position.rst 2011-09-15 13:56:15 +0000
+++ docs/functions/string/position.rst 2012-06-19 08:53:18 +0000
@@ -1,114 +1,5 @@
1Position Functions1Position Functions
2==================2==================
33
4.. _field-function:4
55'TODO'
6FIELD
7-----
8
9The FIELD function returns the index (position) of string arguments (str1, str2, str3, ...)
10
11It returns 0 if the str value is not found.
12
13If each argument is a string, all arguments will be compared as strings, whereas if arguments are numbers, they will be compared as numbers.
14
15Otherwise, the arguments are compared as double.
16
17If str is NULL, the return value is 0 because NULL fails equality comparison with any value. FIELD() is the complement of ELT().
18
19.. code-block:: mysql
20
21 SELECT FIELD('ej', 'Hej', 'ej', 'Heja', 'hej', 'foo');
22
23Returns 2
24
25.. code-block:: mysql
26
27 SELECT FIELD('fo', 'Hej', 'ej', 'Heja', 'hej', 'foo');
28
29Returns 0
30
31.. _find-in-set-function:
32
33FIND_IN_SET
34-----------
35
36Return the index position of the first argument within the second argument
37
38.. code-block:: mysql
39
40 SELECT FIND_IN_SET('2', '1,2,3,4');
41 -> 2
42 SELECT FIND_IN_SET('1', '123');
43 -> 0
44
45.. _instr-function:
46
47INSTR
48-----
49
50INSTR(str, substr) returns the index of the first occurrence of substring str in string substr. Note that this works like LOCATE except the order of the arguments is reversed:
51
52.. code-block:: mysql
53
54 SELECT INSTR('tacosalad', 'salad');
55 -> 5
56 SELECT INSTR('burger', 'salad');
57 -> 0
58
59.. _left-function:
60
61LEFT
62----
63
64Return the leftmost number of characters as specified
65
66.. code-block:: mysql
67
68 SELECT LEFT('drizzled', 7);
69 -> 'drizzle'
70
71.. _insert-function:
72
73INSERT
74------
75
76This function inserts a substring at the specified position up to the specified number of characters.
77
78INSERT(str,pos,len,newstr)
79
80It returns str (a string), with the substring beginning at pos (position) and len (how many characters long) replaced by the newstr.
81
82* INSERT returns the original string if pos is not within the length of the string
83* It replaces the rest of the string from position pos if len is not within the length of the rest of the string
84* It returns NULL if any argument is NULL
85
86.. code-block:: mysql
87
88 SELECT INSERT('Aquatic', 3, 2, 'Me');
89 -> 'AqMetic'
90 SELECT INSERT('Aquatic', -1, 4, 'This');
91 -> 'Aquatic'
92 SELECT INSERT('Aquatic', 3, 100, 'This');
93 -> 'AqThis'
94
95.. _locate-function:
96
97LOCATE
98------
99
100Return the position of the first occurrence of substring.
101
102.. code-block:: mysql
103
104 SELECT LOCATE('salad', 'tacosalad');
105 -> 5
106 SELECT LOCATE('burger', 'salad');
107 -> 0
108
109.. _position-function:
110
111POSITION
112--------
113
114A synonym for LOCATE()
115\ No newline at end of file6\ No newline at end of file
1167
=== modified file 'docs/groupby.rst'
--- docs/groupby.rst 2011-10-23 16:01:37 +0000
+++ docs/groupby.rst 2012-06-19 08:53:18 +0000
@@ -1,9 +1,7 @@
1GROUP BY1GROUP BY
2========2========
33
4The GROUP BY clause is used to extract only those records that fulfill a specified criterion.4'TODO'
5
6SQL GROUP BY Syntax
75
8.. code-block:: mysql6.. code-block:: mysql
97
@@ -12,78 +10,4 @@
12 WHERE column_name operator value10 WHERE column_name operator value
13 GROUP BY column_name11 GROUP BY column_name
1412
15**GROUP BY Clause Example**13'TODO'
16
17The "Activities" table:
18
19+---------+--------------+--------------+-------------+----------+
20|Id |ActivityDate |ActivityType |ActivityCost | userID |
21+=========+==============+==============+=============+==========+
22| 1 |2011-01-02 | Sport |45 |131 |
23+---------+--------------+--------------+-------------+----------+
24| 2 |2011-01-02 | Art |10 |256 |
25+---------+--------------+--------------+-------------+----------+
26| 3 |2011-01-02 | Music |25 |022 |
27+---------+--------------+--------------+-------------+----------+
28| 4 |2011-01-02 | Food |125 |022 |
29+---------+--------------+--------------+-------------+----------+
30| 5 |2011-01-03 | Music |40 |131 |
31+---------+--------------+--------------+-------------+----------+
32| 6 |2011-01-03 | Food |20 |175 |
33+---------+--------------+--------------+-------------+----------+
34
35Running the following simple query
36
37.. code-block:: mysql
38
39 SELECT userID
40 FROM activities
41 GROUP BY userID;
42
43Returns:
44
45+---------+
46| userID |
47+=========+
48| 131 |
49+---------+
50| 256 |
51+---------+
52| 022 |
53+---------+
54| 175 |
55+---------+
56
57(This shows that GROUP BY accepts a column_name and consolidates like customer values.)
58
59However, GROUP BY is much more powerful when used with an aggregate function. Let's say you want to find the total amount spent by each unique User.
60
61You could use the following SQL statement:
62
63.. code-block:: mysql
64
65 SELECT userID,SUM(ActivityCost) AS "Activity Total"
66 FROM Activities
67 GROUP BY userID;
68
69The result-set will look like this:
70
71====== ==============
72userID Activity Total
73====== ==============
74131 85
75256 10
76022 150
77175 20
78====== ==============
79
80With the aggregate SUM() function, SQL can calculate how much each unique user has spent on activities over time.
81
82We can also use the GROUP BY statement on more than one column, like this:
83
84.. code-block:: mysql
85
86 SELECT userID,ActivityDate,SUM(ActivityCost)
87 FROM Activities
88 GROUP BY userID,ActivityDate;
89
90\ No newline at end of file14\ No newline at end of file
9115
=== modified file 'docs/having.rst'
--- docs/having.rst 2011-10-23 16:01:37 +0000
+++ docs/having.rst 2012-06-19 08:53:18 +0000
@@ -1,9 +1,7 @@
1HAVING1HAVING
2======2======
33
4The WHERE keyword cannot be used with aggregate functions, but the HAVING clause can be; this is its primary use.4'TODO'
5
6SQL HAVING Syntax:
75
8.. code-block:: mysql6.. code-block:: mysql
97
@@ -13,58 +11,4 @@
13 GROUP BY column_name11 GROUP BY column_name
14 HAVING aggregate_function(column_name) operator value12 HAVING aggregate_function(column_name) operator value
1513
16**SQL HAVING Example**14'TODO'
17
18Take a look at the "Activities" table:
19
20+---------+--------------+--------------+-------------+----------+
21|Id |ActivityDate |ActivityType |ActivityCost | userID |
22+=========+==============+==============+=============+==========+
23| 1 |2011-01-02 | Sport |45 |131 |
24+---------+--------------+--------------+-------------+----------+
25| 2 |2011-01-02 | Art |10 |256 |
26+---------+--------------+--------------+-------------+----------+
27| 3 |2011-01-02 | Music |25 |022 |
28+---------+--------------+--------------+-------------+----------+
29| 4 |2011-01-02 | Food |125 |022 |
30+---------+--------------+--------------+-------------+----------+
31| 5 |2011-01-03 | Music |40 |131 |
32+---------+--------------+--------------+-------------+----------+
33| 6 |2011-01-03 | Food |20 |175 |
34+---------+--------------+--------------+-------------+----------+
35
36In order to find if any users have spent more than $100 on recreational activities, use the following SQL statement:
37
38.. code-block:: mysql
39
40 SELECT userID,SUM(ActivityCost) FROM Activities
41 GROUP BY userID
42 HAVING SUM(ActivityCost)>100;
43
44The result-set will look like this:
45
46====== ===============
47userID SUM(OrderPrice)
48====== ===============
49022 150
50====== ===============
51
52Now we want to find if userIDs "131", "256", or "175" spent less than $50 on Activities.
53
54We add an ordinary WHERE clause to the SQL statement:
55
56.. code-block:: mysql
57
58 SELECT userID,SUM(ActivityCost) FROM Activities
59 WHERE userID='131' OR userID='256' OR userID="175"
60 GROUP BY userID
61 HAVING SUM(ActivityCost)<50;
62
63The result-set would be:
64
65====== ===============
66userID SUM(OrderPrice)
67====== ===============
68256 10
69175 20
70====== ===============
71\ No newline at end of file15\ No newline at end of file
7216
=== modified file 'docs/insert.rst'
--- docs/insert.rst 2011-03-30 03:12:02 +0000
+++ docs/insert.rst 2012-06-19 08:53:18 +0000
@@ -1,37 +1,4 @@
1Inserting Data1Inserting Data
2==============2==============
33
4In Drizzle you can make use of INSERT in order to insert data into a table.4'TODO'
5
6A type query:
7
8.. code-block:: mysql
9
10 INSERT INTO A VALUES ("1");
11
12INSERT statements that use VALUES syntax can insert multiple rows. To do this, use the multi row VALUES syntax (include multiple lists of column values, each enclosed within parentheses and separated by commas):
13
14.. code-block:: mysql
15
16 INSERT INTO music (artist, album, date_prod, genre) VALUES
17 ('Beatles', 'Abbey Road', '1969-09-26', 'rock'),
18 ('The Velvet Underground', 'The Velvet Underground', '1969-03-05', 'rock');
19
20or:
21
22.. code-block:: mysql
23
24 INSERT INTO table_1 (a,b,c) VALUES(1,2,3),(4,5,6),(7,8,9);
25
26The following statement is incorrect since the number of values in the list does not match the number of column names:
27
28.. code-block:: mysql
29
30 INSERT INTO table_1 (a,b,c) VALUES(1,2,3,4,5,6,7,8,9);
31
32VALUE is a synonym for VALUES where performing a single or multirow INSERT.
33
34Performance
35-----------
36
37A multi-row INSERT involving three rows will require roughly one third of the time required to execute the three single-row statements. This performance improvement can become quite significant over a large number of statements.
38\ No newline at end of file5\ No newline at end of file
396
=== modified file 'docs/join.rst'
--- docs/join.rst 2011-11-06 00:00:03 +0000
+++ docs/join.rst 2012-06-19 08:53:18 +0000
@@ -1,60 +1,7 @@
1JOIN1JOIN
2====2====
33
4The JOIN keyword is used in an SQL statement to query data from two or more tables, based on a relationship between certain columns in these tables.4'TODO'
5
6Queries can access multiple tables at once, or access the same table in such a way that multiple rows of the table are being processed at the same time. For instance, in order to list all the 'interest' records together with the location of the associated city. To do this, it's necessary to compare the city column of each row of the 'Interests" table with the name column of all rows in the cities table, and select the pairs of rows where these values match. As such, a JOIN statement involves combining records from two tables by using values common to each.
7
8Take the "Interests" table:
9
10+---------+--------------+--------------+-------------+----------+
11|Id |DateAdded |InterestType |Name | userID |
12+=========+==============+==============+=============+==========+
13| 1 |2011-01-02 | Sport |45 |2 |
14+---------+--------------+--------------+-------------+----------+
15| 2 |2011-01-02 | Art |10 |4 |
16+---------+--------------+--------------+-------------+----------+
17| 3 |2011-01-02 | Music |25 |1 |
18+---------+--------------+--------------+-------------+----------+
19| 4 |2011-01-02 | Food |125 |1 |
20+---------+--------------+--------------+-------------+----------+
21| 5 |2011-01-03 | Music |40 |2 |
22+---------+--------------+--------------+-------------+----------+
23| 6 |2011-01-03 | Food |20 |3 |
24+---------+--------------+--------------+-------------+----------+
25
26
27Note that the "Id" column is the primary key in the "Persons" table. This means that no two rows can have the same "Id"; it distinguishes two interests even if they have the same name or userID.
28
29Next, we have the "Persons" table:
30
31+---------+------------+----------+----------+--------+
32|userId |LastName |FirstName |Address | City |
33+=========+============+==========+==========+========+
34| 1 | Larson | Sue |3 Cherry | Chicago|
35+---------+------------+----------+----------+--------+
36| 2 | Roberts | Teri |21 Brown | Chicago|
37+---------+------------+----------+----------+--------+
38| 3 | Peterson | Kari |30 Mell | Reno |
39+---------+------------+----------+----------+--------+
40| 4 | Anderson | Kyle |435 Tyler | Dayton |
41+---------+------------+----------+----------+--------+
42
43The "userID" column is the primary key in the "Persons" table; in the "Persons" table, it can be used to identify users without using their names. Therefore, the relationship between the two tables above is the "userId" column.
44
45Different kinds of SQL JOINs
46----------------------------
47
48Here are the types of JOIN you can use, and the differences between them:
49
50 **JOIN:** Return rows when there is at least one match in both tables
51
52 **LEFT JOIN:** Return all rows from the left table, even if there are no matches in the right table
53
54 **RIGHT JOIN:** Return all rows from the right table, even if there are no matches in the left table
55
56 **CROSS JOIN:** Return rows when there is a match in one of the tables
57
585
59.. note::6.. note::
60 Implicit cartesian products of the form ``SELECT * FROM t1, t2``7 Implicit cartesian products of the form ``SELECT * FROM t1, t2``
618
=== modified file 'docs/load_data_infile.rst'
--- docs/load_data_infile.rst 2011-03-17 16:54:26 +0000
+++ docs/load_data_infile.rst 2012-06-19 08:53:18 +0000
@@ -1,39 +1,4 @@
1LOAD DATA INFILE1LOAD DATA INFILE
2=================2=================
33
4While the INSERT statement loads one record at a time into a table, LOAD DATA INFILE imports data from an external text file into a table, and does so very rapidly. The file name must be given as a literal string.4'TODO'
5
6For example:
7
8.. code-block:: mysql
9
10 LOAD DATA LOCAL INFILE '/home/user/names.txt' INTO TABLE names;
11
12Then check that your data was loaded correctly:
13
14.. code-block:: mysql
15
16 SELECT * FROM names;
17
18Options
19--------
20
21LOAD DATA INFILE has some options that can be used to specify the format for the text file and how the data is imported. Above, the LOCAL option specifies the client machine as the location of the text file. When connecting to a Drizzle server, the file will be read directly from the server as long as the LOCAL option is omitted.
22
23The REPLACE option replaces table rows with the same primary key in the text file. For example:
24
25.. code-block:: mysql
26
27 LOAD DATA LOCAL INFILE '/home/user/names.txt' REPLACE INTO TABLE names;
28
29The IGNORE option says to skip any rows that duplicate existing rows with the same primary key, and follows the same syntax as REPLACE. The IGNORE number LINES option can be used to ignore lines at the start of the file. For example, you can use IGNORE 1 LINES to skip over a row containing column names:
30
31.. code-block:: mysql
32
33 LOAD DATA LOCAL INFILE '/home/user/names.txt' INTO TABLE names IGNORE 1 LINES;
34
35The FIELDS TERMINATED BY option can be used when importing from a comma separated value (CSV) file. (It specifies that the fields will be separated by a character other than a tab, such as a comma.) For example:
36
37.. code-block:: mysql
38
39 LOAD DATA LOCAL INFILE '/home/user/names.csv' REPLACE INTO TABLE names FIELDS TERMINATED BY ',';
40\ No newline at end of file5\ No newline at end of file
416
=== modified file 'docs/orderby.rst'
--- docs/orderby.rst 2011-10-23 16:01:37 +0000
+++ docs/orderby.rst 2012-06-19 08:53:18 +0000
@@ -1,7 +1,7 @@
1ORDER BY1ORDER BY
2========2========
33
4The ORDER BY keyword is used to sort the result-set by column; by default, it sorts the records in ascending order.4'TODO'
55
6SQL ORDER BY Syntax:6SQL ORDER BY Syntax:
77
@@ -11,49 +11,4 @@
11 FROM table_name11 FROM table_name
12 ORDER BY column_name(s) ASC|DESC;12 ORDER BY column_name(s) ASC|DESC;
1313
14**ORDER BY Example**14'TODO'
15
16The "Persons" table:
17
18+---------+------------+----------+----------+--------+
19|Id |LastName |FirstName |Address | City |
20+=========+============+==========+==========+========+
21| 1 | Larson | Sue |3 Cherry | Chicago|
22+---------+------------+----------+----------+--------+
23| 2 | Roberts | Teri |21 Brown | Chicago|
24+---------+------------+----------+----------+--------+
25| 3 | Peterson | Kari |30 Mell | Reno |
26+---------+------------+----------+----------+--------+
27
28To select all the persons from the table above, and also sort them by their last name, use the following SELECT statement:
29
30.. code-block:: mysql
31
32 SELECT * FROM Persons
33 ORDER BY LastName;
34
35The result-set will look like this:
36
37+---------+------------+----------+----------+--------+
38|Id |LastName |FirstName |Address | City |
39+=========+============+==========+==========+========+
40| 1 | Larson | Sue |3 Cherry | Chicago|
41+---------+------------+----------+----------+--------+
42| 3 | Peterson | Kari |30 Mell | Reno |
43+---------+------------+----------+----------+--------+
44| 2 | Roberts | Teri |21 Brown | Chicago|
45+---------+------------+----------+----------+--------+
46
47Without using "ORDERBY" in the following query, the result-set will be non-deterministic, and could returned matching rows in a different order for each query.
48
49ORDER BY DESC can be used to reverse the order of the result set.
50
51.. code-block:: mysql
52
53 SELECT * FROM Persons
54 ORDER BY LastName DESC;
55
56
57.. todo::
58
59 add something about how ORDER BY is executed. index scan vs filesort
60\ No newline at end of file15\ No newline at end of file
6116
=== modified file 'docs/queries.rst'
--- docs/queries.rst 2011-02-15 22:03:42 +0000
+++ docs/queries.rst 2012-06-19 08:53:18 +0000
@@ -1,18 +1,13 @@
1Executing Queries1Executing Queries
2=================2=================
33
4Queries retrieve data from a database based on specific criteria. They4'TODO'
5are performed with the declarative SELECT statement, which has no
6persistent effects on the database. SELECT simply retrieves data from
7one or more tables, or expressions.
8
9A query includes a list of columns to be included in a result set; an example of this would be:
105
11.. code-block:: mysql6.. code-block:: mysql
127
13 SELECT * FROM table_name;8 SELECT * FROM table_name;
149
15SELECT * FROM is an example of using SELECT with clauses. The select clause specifies the columns you want to retrieve. The from clause specifies the tables to search. 10'TODO'
1611
17Keywords and clauses include:12Keywords and clauses include:
1813
@@ -34,8 +29,4 @@
34 FROM table_name29 FROM table_name
35 WHERE first_column_name > 1000;30 WHERE first_column_name > 1000;
3631
37The column names that follow the SELECT keyword determine the columns that will be returned in the results. You can select as many column names that you'd like, or you can use a * to select all columns (as shown in the first example above). The order in which they are specified will be reflected in your query results.32'TODO'
38
39The table name that follows the keyword FROM specifies the table that will be queried to retrieve the desired results.
40
41The WHERE clause (optional) specifies the data values or rows to be returned or displayed, based on the criteria described after the keyword WHERE.
42\ No newline at end of file33\ No newline at end of file
4334
=== modified file 'docs/rename.rst'
--- docs/rename.rst 2011-11-06 00:00:03 +0000
+++ docs/rename.rst 2012-06-19 08:53:18 +0000
@@ -1,23 +1,13 @@
1RENAME1RENAME
2======2======
33
4Rename a table, or group of tables.4'TODO'
5
6If you have an existing table old_name, you can create another table new_name; it will be empty but reptant he same structure, and then replace the existing table with the empty one as follows (assuming backup_table does not already exist):
75
8.. code-block:: mysql6.. code-block:: mysql
97
10 CREATE TABLE new_name (...);8 CREATE TABLE new_name (...);
11 RENAME TABLE old_name TO backup_table, new_name TO old_name;9 RENAME TABLE old_name TO backup_table, new_name TO old_name;
1210
13When using a statement to rename more than one table, the order of operations are done from left to right. To swap two table names, use the following (assuming tmp_table does not already exist):11'TODO'
14
15.. code-block:: mysql
16
17 RENAME TABLE old_name TO tmp_table,
18 new_name TO old_name,
19 tmp_table TO new_name;
20
21While RENAME is running, no other session can access any of the involved tables.
2212
23.. seealso:: :doc:`/alter_table`13.. seealso:: :doc:`/alter_table`
2414
=== modified file 'docs/resources/ascii_chart.rst'
--- docs/resources/ascii_chart.rst 2011-02-23 15:33:37 +0000
+++ docs/resources/ascii_chart.rst 2012-06-19 08:53:18 +0000
@@ -1,103 +1,4 @@
1ASCII Conversion Chart1ASCII Conversion Chart
2=======================2=======================
33
4========== =========== ============= ================= ================== 4'TODO'
5 Binary Octal Decimal Hexadecimal Character
6========== =========== ============= ================= ==================
7100000 40 32 20 ``space character``
8100001 41 33 21 ``!``
9100010 42 34 22 ``"``
10100011 43 35 23 ``#``
11100100 44 36 24 ``$``
12100101 45 37 25 ``%``
13100110 46 38 26 ``&``
14100111 47 39 27 ``'``
15101000 50 40 28 ``(``
16101001 51 41 29 ``)``
17101010 52 42 2A ``*``
18101011 53 43 2B ``+``
19101100 54 44 2C ``,``
20101101 55 45 2D ``-``
21101110 56 46 2E ``.``
22101111 57 47 2F ``/``
23110000 60 48 30 ``0``
24110001 61 49 31 ``1``
25110010 62 50 32 ``2``
26110011 63 51 33 ``3``
27110100 64 52 34 ``4``
28110101 65 53 35 ``5``
29110110 66 54 36 ``6``
30110111 67 55 37 ``7``
31111000 70 56 38 ``8``
32111001 71 57 39 ``9``
33111010 72 58 3A ``:``
34111011 73 59 3B ``;``
35111100 74 60 3C ``<``
36111101 75 61 3D ``=``
37111110 76 62 3E ``>``
38111111 77 63 3F ``?``
391000000 100 64 40 ``@``
401000001 101 65 41 ``A``
411000010 102 66 42 ``B``
421000011 103 67 43 ``C``
431000100 104 68 44 ``D``
441000101 105 69 45 ``E``
451000110 106 70 46 ``F``
461000111 107 71 47 ``G``
471001000 110 72 48 ``H``
481001001 111 73 49 ``I``
491001010 112 74 4A ``J``
501001011 113 75 4B ``K``
511001100 114 76 4C ``L``
521001101 115 77 4D ``M``
531001110 116 78 4E ``N``
541001111 117 79 4F ``O``
551010000 120 80 50 ``P``
561010001 121 81 51 ``Q``
571010010 122 82 52 ``R``
581010011 123 83 53 ``S``
591010100 124 84 54 ``T``
601010101 125 85 55 ``U``
611010110 126 86 56 ``V``
621010111 127 87 57 ``W``
631011000 130 88 58 ``X``
641011001 131 89 59 ``Y``
651011010 132 90 5A ``Z``
661011011 133 91 5B ``[``
671011100 134 92 5C ``\``
681011101 135 93 5D ``]``
691011110 136 94 5E ``^``
701011111 137 95 5F ``_``
711100000 140 96 60 :literal:`\``
721100001 141 97 61 ``a``
731100010 142 98 62 ``b``
741100011 143 99 63 ``c``
751100100 144 100 64 ``d``
761100101 145 101 65 ``e``
771100110 146 102 66 ``f``
781100111 147 103 67 ``g``
791101000 150 104 68 ``h``
801101001 151 105 69 ``i``
811101010 152 106 6A ``j``
821101011 153 107 6B ``k``
831101100 154 108 6C ``l``
841101101 155 109 6D ``m``
851101110 156 110 6E ``n``
861101111 157 111 6F ``o``
871110000 160 112 70 ``p``
881110001 161 113 71 ``q``
891110010 162 114 72 ``r``
901110011 163 115 73 ``s``
911110100 164 116 74 ``t``
921110101 165 117 75 ``u``
931110110 166 118 76 ``v``
941110111 167 119 77 ``w``
951111000 170 120 78 ``x``
961111001 171 121 79 ``y``
971111010 172 122 7A ``z``
981111011 173 123 7B ``{``
991111100 174 124 7C ``|``
1001111101 175 125 7D ``}``
1011111110 176 126 7E ``~``
102========== =========== ============= ================= ==================
103
1045
=== modified file 'docs/savepoints.rst'
--- docs/savepoints.rst 2011-02-15 22:03:42 +0000
+++ docs/savepoints.rst 2012-06-19 08:53:18 +0000
@@ -1,11 +1,11 @@
1SAVEPOINT1SAVEPOINT
2=========2=========
33
4A savepoint is a marker inside a transaction that allows all commands that are executed after it was established to be rolled back. It effectively restores the transaction state to what it was at the time of the savepoint. ::4'TODO' ::
55
6 SAVEPOINT identifier6 SAVEPOINT identifier
77
8This sets a savepoint that can be returned to in the current transaction. The "identifier" is the name given to the new savepoint. If the identifier has already been used then the original identifier is replaced. Example:8'TODO'
99
10.. code-block:: mysql10.. code-block:: mysql
1111
@@ -15,4 +15,4 @@
15 INSERT INTO t1 values (2);15 INSERT INTO t1 values (2);
16 ROLLBACK TO SAVEPOINT A;16 ROLLBACK TO SAVEPOINT A;
1717
18Will only roll back the second insert statement.18'TODO'
1919
=== modified file 'docs/start_transaction.rst'
--- docs/start_transaction.rst 2011-02-23 13:08:09 +0000
+++ docs/start_transaction.rst 2012-06-19 08:53:18 +0000
@@ -1,7 +1,7 @@
1START TRANSACTION1START TRANSACTION
2======================2======================
33
4A transaction can be started with either the BEGIN or START TRANSACTION statements. It can also be started by any statement when AUTOCOMMIT is disabled. A transaction can then run until either the connection to the database is dropped (in which case it is rolled back), or an explicit rollback or a commit command is sent.4'TODO'
55
6.. code-block:: mysql6.. code-block:: mysql
77
88
=== modified file 'docs/string_data_types.rst'
--- docs/string_data_types.rst 2011-03-17 17:15:30 +0000
+++ docs/string_data_types.rst 2012-06-19 08:53:18 +0000
@@ -1,12 +1,11 @@
1String Data Types1String Data Types
2=================2=================
33
4The string types in Drizzle are explained in the following groupings:
54
6VARCHAR and VARBINARY5VARCHAR and VARBINARY
7---------------------6---------------------
87
9A VARCHAR or VARBINARY type is used to store variable length data. Indexes on these types are by default the full length of the data stored. The only difference between the two types is the COLLATION which is used. VARBINARY uses a binary collation for all index usage.8'TODO'
109
11.. note::10.. note::
1211
@@ -16,15 +15,15 @@
16TEXT and BLOB15TEXT and BLOB
17-------------16-------------
1817
19A TEXT or BLOB type is used to store data which is over XXX in size. Indexes on these types must specify the number of character or bytes which should be used. The only difference between the two types is the COLLATION which is used. A BLOB uses a binary collation for all index usage.18'TODO'
2019
21ENUM20ENUM
22----21----
2322
24Enum (enumerated) types are static lists of strings that are defined on table creation. They can be used to represent a collection of string types that are sorted based on the order that they are created.23'TODO'
2524
2625
27UTF-826UTF-8
28------27------
2928
30Drizzle stores its string data in an UTF-8 format, and does not support a multitude of language encodings and collations.
31\ No newline at end of file29\ No newline at end of file
30'TODO'
32\ No newline at end of file31\ No newline at end of file
3332
=== modified file 'docs/tables.rst'
--- docs/tables.rst 2011-01-14 05:11:22 +0000
+++ docs/tables.rst 2012-06-19 08:53:18 +0000
@@ -1,17 +1,7 @@
1Tables1Tables
2======2======
33
4A table makes up a collection of :doc:`/columntypes` that4'TODO'
5can be joined together in order to create relational result sets.
6
7Each record in the table is called a row, and a table can have an infinite
8set of rows. Each row represents one piece of data, and each column can
9be thought of as representing a component of that piece of data.
10
11So, for example, if we have a table for a customer information, then
12the columns may include information such as First Name, Last Name,
13Address, City, Country, Birth Date, and so on. As a result, tables have
14column headers, which specify the data types for that particular column.
155
16.. toctree:: 6.. toctree::
17 :maxdepth: 27 :maxdepth: 2
188
=== modified file 'docs/transactional.rst'
--- docs/transactional.rst 2011-02-23 13:08:09 +0000
+++ docs/transactional.rst 2012-06-19 08:53:18 +0000
@@ -9,7 +9,7 @@
9 rollback9 rollback
10 savepoints10 savepoints
1111
12The essence of a transaction is that it groups multiple steps into a single, all-or-nothing operation. Drizzle is a transactional database by default and by design, meaning that changes and queries to the database appear to be Atomic, Consistent, Isolated, and Durable (ACID). This means that Drizzle implements `serializable <http://en.wikipedia.org/wiki/Serializability>`_, ACID transactions, even if the transaction is interrupted.12Drizzle is a transactional database by default and by design, meaning that changes and queries to the database appear to be Atomic, Consistent, Isolated, and Durable (ACID). This means that Drizzle implements `serializable <http://en.wikipedia.org/wiki/Serializability>`_, ACID transactions, even if the transaction is interrupted.
1313
14NOTE: Drizzle still supports non-transactional storage engines, and if these are used then you will not get transactional behaviour with them. The default engine is transactional.14NOTE: Drizzle still supports non-transactional storage engines, and if these are used then you will not get transactional behaviour with them. The default engine is transactional.
1515
1616
=== modified file 'docs/update.rst'
--- docs/update.rst 2011-02-16 22:57:39 +0000
+++ docs/update.rst 2012-06-19 08:53:18 +0000
@@ -1,20 +1,4 @@
1Updating Data1Updating Data
2=============2=============
33
4In Drizzle you can make use of UPDATE to modify an existing record in a table.4'TODO'
5
6An example query:
7
8.. code-block:: mysql
9
10 UPDATE TABLE_1 SET a="1" WHERE <condition>;
11
12Multi-table delete and multi-table update code was removed from Drizzle.
13
14Multi-update/delete can be accomplished through subqueries. For example:
15
16.. code-block:: mysql
17
18 UPDATE tableX SET tableXfield = (SELECT MAX(tableY.tableYfield) FROM tableY WHERE tableX.tableXfield = tableY.tableYfield)
19
20In other database frameworks, multi-update and multi-delete are used to change information in *one* table, but the rows to change are determined by using more than one table. In that case, subqueries work to address the issue of changing information in one table based on information in more than one table.
215
=== modified file 'docs/uuid_data_type.rst'
--- docs/uuid_data_type.rst 2011-02-24 14:52:15 +0000
+++ docs/uuid_data_type.rst 2012-06-19 08:53:18 +0000
@@ -1,16 +1,6 @@
1UUID Data Type1UUID Data Type
2==============2==============
33
4The data type uuid stores Universally Unique Identifiers (UUID). Some systems refer to this data type as "globally unique identifier", or GUID, instead. 4'TODO'
5
6This identifier is a 128-bit quantity that is generated by an algorithm designed to make it very unlikely that the same identifier will be generated by anyone else in the world using the same algorithm. The purpose of UUIDs is to enable distributed systems to uniquely identify information without significant central coordination.
7
8sequence generators, which are only unique within a single database.
9
10A UUID consists of 32 hexadecimal digits, displayed in 5 groups separated by hyphens, in the form 8-4-4-4-12 for a total of 36 characters (32 digits and 4 hyphens). For example:
11
12550e8400-e29b-41d4-a716-446655440000
13
14UUIDs are documented as part of ISO/IEC 11578:1996 "Information technology – Open Systems Interconnection – Remote Procedure Call (RPC)" and more recently in ITU-T Rec. X.667 | ISO/IEC 9834-8:2005. The IETF published Standards Track :rfc:`4122` that is technically equivalent with ITU-T Rec. X.667 | ISO/IEC 9834-8.
155
16Drizzle uses libuuid to generate UUID values.6Drizzle uses libuuid to generate UUID values.
177
=== modified file 'docs/where.rst'
--- docs/where.rst 2011-10-23 16:01:37 +0000
+++ docs/where.rst 2012-06-19 08:53:18 +0000
@@ -1,9 +1,7 @@
1WHERE1WHERE
2=====2=====
33
4The WHERE clause is used to extract only those records that fulfill a specified criterion.4'TODO'
5
6Simple SQL WHERE Syntax:
75
8.. code-block:: mysql6.. code-block:: mysql
97
@@ -11,33 +9,4 @@
11 FROM table_name9 FROM table_name
12 WHERE column_name operator value10 WHERE column_name operator value
13 11
14**Simple WHERE Clause Example**12'TODO' (examples)
15
16The "Persons" table:
17
18+---------+------------+----------+----------+--------+
19|Id |LastName |FirstName |Address | City |
20+=========+============+==========+==========+========+
21| 1 | Larson | Sue |3 Cherry | Chicago|
22+---------+------------+----------+----------+--------+
23| 2 | Roberts | Teri |21 Brown | Chicago|
24+---------+------------+----------+----------+--------+
25| 3 | Peterson | Kari |30 Mell | Reno |
26+---------+------------+----------+----------+--------+
27
28If you want to select only the persons living in the city "Chicago" from the table above, use the following SELECT statement:
29
30.. code-block:: mysql
31
32 SELECT * FROM Persons
33 WHERE City='Chicago'
34
35The result-set will look like this:
36
37+---------+------------+----------+----------+--------+
38| Id |LastName |FirstName |Address |City |
39+=========+============+==========+==========+========+
40|1 | Larson | Sue |3 Cherry | Chicago|
41+---------+------------+----------+----------+--------+
42|2 | Roberts | Teri |21 Brown | Chicago|
43+---------+------------+----------+----------+--------+
44\ No newline at end of file13\ No newline at end of file

Subscribers

People subscribed via source and target branches