This repository has been archived by the owner on Jan 27, 2020. It is now read-only.
forked from kornelski/mysqlcompat
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME
161 lines (107 loc) · 4.53 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
MySQL Compatibility Functions
=============================
Authors: Chris Kings-Lynne, Gavin Sherry & Others
Contributors: Michael Fuhr, Robert Treat, Marti Raudsepp
Current maintainer: Marc G Fournier
Introduction
------------
This project is a collection of functions, aggregates,
operators and casts that make PostgreSQL mimic MySQL as
closely as possible.
To use the project, you can either find and install the
few functions that you need, or run all the .sql files
to install the complete compatibility environment.
This can be an immense time-saver when porting large applications
that rely heavily on certain MySQL functions.
Versions of PostgreSQL supported
--------------------------------
This package has been tested on PostgreSQL 8.2.x through 9.5.x
Installation
------------
First, you must have created a database in PostgreSQL.
Then, a few of the functions are written in the PL/PgSQL
language handler. If you use these functions you need
to install that handler, like this:
createlang plpgsql <dbname>
Next, load any (or all) of the .sql files into that
database, eg:
psql -f all.sql <dbname>
Or, to install a particular subset of functions:
psql -f sql_bits/datetime.sql <dbname>
Or, if you only want to install a particular function, just
copy and paste it into psql directly, taking care to install any
of the function's listed dependencies.
You will see a series of CREATE (and other) tags
that indicates each successful command. Read any
other messages that appear as they may be errors.
Alternatively, you can execute the SQL scripts via
a GUI tool such as pgAdmin (www.pgadmin.org) or
phpPgAdmin (phppgadmin.sf.net).
Uninstall
---------
The mysqlcompat_uninstall.sql script contains drop commands for every object in
this library. To drop everything for example, run:
psql -f sql/mysqlcompat_uninstall.sql <dbname>
Then, if you have no further need for the PL/PgSQL language handler
you can drop it as follows:
droplang plpgsql <dbname>
Usage
-----
If you have followed the installation notes above, then
all the MySQL compatibility functions, operators and
aggregates will be installed in the public schema of your
database. This means you can use them without any special
qualification.
Here are some examples:
SELECT true && false;
=> f
SELECT format(1234.432, 4);
=> 1,234.4320
General Compatibility Notes
---------------------------
In some cases (obviously) MySQL is just too different
from PostgreSQL to allow re-implementation of features.
This usually happens when a MySQL feature would require
changing the PostgreSQL SQL grammar.
Any function name that begins with '_' in this library
is a "private" function that should not be called directly.
Here is a list of major incompatibilities:
* Boolean vs. Integer
MySQL has no boolean type, and instead it uses the integer
values 0 and 1 as boolean results. PostgreSQL has a true
boolean type and it can accept 0, 1, true, false, 't' or 'f'
as values. However, by default all boolean values are SHOWN
as either 't' or 'f'.
Since PostgreSQL already has most of MySQL's logical operators
(eg. OR, AND, etc.) which all return 't' or 'f' to mean true or
false, then there isn't much point returning 0 or 1 for the
two or three logical operators that this library implements.
This is just something you need to deal with during porting.
Tip: PostgreSQL includes a boolean to integer explicit cast, eg:
SELECT true::integer + 1;
=> 2
* Time vs. Interval
MySQL has no interval type, and hence often confuses 'time'
with 'interval'. For example, '123:13:56' is a valid interval
but is an invalid time.
This library uses the PostgreSQL interval type for many of the
MySQL functions that require or return times. In general
this won't make any difference.
* Intervals
In MySQL, intervals are not quoted, eg:
SELECT ADDDATE('1998-01-02', INTERVAL 31 DAY);
In PostgreSQL the 31 DAY part needs to be quoted:
SELECT ADDDATE('1998-01-02', INTERVAL '31 DAY');
* Missing operators
XOR, DIV and MOD named operators cannot be implemented. Use
#, / (with integer casts) and % instead.
* Case-sensitive strings
All PostgreSQL strings are case-sensitive. All MySQL strings are
case-insensitive by default. Any functions in this library that
implement string comparison use CASE-SENSITIVE comparison, just
like all the other PostgreSQL string functions.
* Failure to find overloaded functions
In some cases (due to the way PostgreSQL works) you will need
to add explicit casts to some function calls. An explicit cast
looks like this:
SELECT ADDTIME('01:00:00.999999'::interval, '02:00:00.999998');