my2pg.pl1
Mysql -> postgresql dump conversion utility.
Usage
mysqldump db
⎪
./my2pg.pl
[-n]
>
pgsqldump.sql
vi libtypes.c
make
psql database
<
pgsqldump.txt
where
Overview
my2pg utility attempts to convert MySQL database dump to Postgres's one. my2pg performs such conversions:
- Type conversion.
-
It tries to find proper Postgres type for each column. Unknown types are silently pushing to output dump; ENUM and SET types implemented via user types (C source for such types can be found in
libtypes.cfile);
- Identifiers double-quotation.
-
All column and table names should be enclosed to double-quotes to prevent interferension with reserved words;
- Converting
-
AUTO_INCREMENT fields to SERIAL. Actually, creating the sequence and setting default value to nextval('seq'), well, you know :)
- Converting
-
KEY(field) to CREATE INDEX i_field on table (field);
- The same
-
for UNIQUE keys;
- Indices
-
are creating AFTER rows insertion (to speed up the load);
- Translates '#'
-
MySQL comments to ANSI SQL '--'
It encloses dump in transaction block to prevent single errors during data load.
Options
My2pg takes the following command-line options:
-
-n -
Convert *CHAR DEFAULT '' NOT NULL types to *CHAR NULL. Postgres can't load empty '' strings in NOT NULL fields.
-
-d -
Add double quotes around table and column names
-
-h -
Show usage banner.
Side effects
- creates
-
file
libtypes.cin current directory overwriting existed file without any checks;
- the same
-
for Makefile.
Credits
Jeff Waugh <[email protected]> Joakim Lemström <[email protected]> ⎪⎪ <[email protected]> Yunliang Yu <[email protected]> Brad Hilton <[email protected]>