Skip to content

Commit 2258382

Browse files
committed
Update readme
1 parent 5aeee76 commit 2258382

File tree

1 file changed

+51
-39
lines changed

1 file changed

+51
-39
lines changed

README.md

+51-39
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,38 @@
11
# mysql_generate_series: generate_series for MySQL
22

3-
mysql_generate_series is a MySQL version of PostgreSQL's [generate_series](http://www.postgresql.org/docs/9.4/static/functions-srf.html) functions.
3+
mysql_generate_series is a MySQL version of PostgreSQL's [generate_series](http://www.postgresql.org/docs/current/static/functions-srf.html) functions.
44

5-
This version is (heavily) adapted from the original by Gabriel Bordeaux and seeks to simplify the method call and make the MySQL version parameters follow the PostgreSQL version insofar as that is possible.
5+
This version is (heavily) adapted from the original and seeks to simplify the method call and make the MySQL version parameters follow the PostgreSQL version insofar as that is possible.
66

7-
It offers a single method taking 3 parameters:
8-
* generate_series(start, stop, step): and delivers a series from "start" to "stop" incrementing by "step".
7+
It offers a single method `generate_series(start, stop, step)` to deliver a series from `start` to `stop` incrementing by `step`.
98

109
Calling the method generates no output but instead creates a temporary table called `series_tmp` in the current database which can be used in joins and sub-queries in the current session.
1110

12-
All parameters are INTEGER or strings which are representative of INTEGER, DATE, DATETIME and INTERVAL depending on the type of series being generated
11+
All parameters are `INTEGER` or strings which are representative of `INTEGER`, `DATE`, `DATETIME` and `INTERVAL` depending on the type of series being generated
1312

14-
### INTEGER Series
15-
For integer ranges the three parameters are all INTEGER or string representations of numbers ("strumbers" if you prefer)
13+
## Installation
1614

17-
either
15+
Install the methods from [sql/generate_series.sql](sql/generate_series.sql).
1816

19-
* CALL generate_series(1, 20, 1);
20-
or
21-
* CALL generate_series('1', '20', '1');
17+
## INTEGER Series
18+
19+
For integer ranges the three parameters are all INTEGER or string representations of numbers.
20+
21+
### Usage
22+
23+
```sql
24+
CALL generate_series(1, 20, 1);
25+
```
2226

2327
Will create and populate `series_tmp` with INTEGER values from 1 to 20, incrementing by 1.
2428

29+
### Example
30+
2531
```sql
2632
mysql> CALL generate_series( 1 , 10 , 1);
2733
Query OK, 0 rows affected (0.05 sec)
2834

29-
mysql> describe series_tmp;
35+
mysql> DESC series_tmp;
3036
+--------+------------+------+-----+---------+-------+
3137
| Field | Type | Null | Key | Default | Extra |
3238
+--------+------------+------+-----+---------+-------+
@@ -52,18 +58,22 @@ mysql> SELECT * FROM `series_tmp`;
5258
10 rows in set (0.00 sec)
5359
```
5460

55-
### DATE Series
56-
For date ranges the "start" and "stop" parameters are string representations of dates and "step" represents the INTERVAL
61+
## DATE Series
62+
63+
For date ranges the `start` and `stop` parameters are string representations of dates and `step` represents the `INTERVAL`.
5764

58-
e.g.
65+
### Usage
5966

60-
* CALL generate_series('2018-01-01','2018-12-31','INTERVAL 1 DAY');
67+
```sql
68+
CALL generate_series('2018-01-01','2018-12-31','INTERVAL 1 DAY');
69+
```
6170

71+
### Example
6272
```sql
6373
mysql> CALL generate_series('2018-01-01','2018-12-31','INTERVAL 1 MONTH');
6474
Query OK, 0 rows affected (0.08 sec)
6575

66-
mysql> describe series_tmp;
76+
mysql> DESC series_tmp;
6777
+--------+------+------+-----+---------+-------+
6878
| Field | Type | Null | Key | Default | Extra |
6979
+--------+------+------+-----+---------+-------+
@@ -92,18 +102,23 @@ mysql> SELECT * FROM `series_tmp`;
92102
```
93103

94104

95-
### DATETIME Series
96-
For datetime ranges the "start" and "stop" parameters are datetimes and "step" represents the INTERVAL.
105+
## DATETIME Series
97106

98-
e.g.
107+
For datetime ranges the `start` and `stop` parameters are datetimes and `step` represents the `INTERVAL`.
99108

100-
* CALL generate_series('2018-01-01 00:00:00', '2018-01-01 23:59:59', 'INTERVAL 1 SECOND');
109+
### Usage
110+
111+
```sql
112+
CALL generate_series('2018-01-01 00:00:00', '2018-01-01 23:59:59', 'INTERVAL 1 SECOND');
113+
```
114+
115+
### Example
101116

102117
```sql
103118
mysql> CALL generate_series('2018-01-01 00:00:00', '2018-01-01 23:59:00', 'INTERVAL 1 MINUTE');
104119
Query OK, 0 rows affected (0.07 sec)
105120

106-
mysql> describe series_tmp;
121+
mysql> DESC series_tmp;
107122
+--------+----------+------+-----+---------+-------+
108123
| Field | Type | Null | Key | Default | Extra |
109124
+--------+----------+------+-----+---------+-------+
@@ -133,26 +148,23 @@ mysql> SELECT * FROM `series_tmp`;
133148
1440 rows in set (0.00 sec)
134149
```
135150

136-
### INTERVALS
137-
The following INTERVAL types are supported:
138-
139-
* SECOND
140-
* MINUTE
141-
* HOUR
142-
* DAY
143-
* WEEK
144-
* MONTH
145-
* YEAR
151+
## INTERVALS
146152

153+
The following INTERVAL types are supported:
147154

148-
### Installation
149-
150-
* Install the methods from [sql/generate_series.sql](sql/generate_series.sql)
155+
- `SECOND`
156+
- `MINUTE`
157+
- `HOUR`
158+
- `DAY`
159+
- `WEEK`
160+
- `MONTH`
161+
- `YEAR`
151162

163+
## Other examples
152164

153165
### Inserting in a table from a series
154166

155-
MySQL does not support functions returning table so the procedure must be run before the data can be used from `series_tmp`.
167+
MySQL does not support functions returning tables so the procedure must be run before the data can be used from `series_tmp`.
156168

157169
The following example shows how to insert multiple rows in MySQL tables easily:
158170

@@ -258,11 +270,11 @@ mysql> SELECT series_tmp.series, test2.a, test2.b
258270
24 rows in set (0.00 sec)
259271
```
260272

261-
### Tips and tricks
273+
## Tips and tricks
262274

263-
* The temporary table used to store results `series_tmp` is dropped and recreated on each call to generate_series(). As a temporary table, `series_tmp` will only be available within the current session and to the current user. It will also automatically dropped when the connection is closed.
275+
The temporary table used to store results `series_tmp` is dropped and recreated on each call to generate_series(). As a temporary table, `series_tmp` will only be available within the current session and to the current user. It will also automatically dropped when the connection is closed.
264276

265-
### Authors
277+
## Authors
266278

267279
**Gabriel Bordeaux**
268280

0 commit comments

Comments
 (0)