my2pg.pl(1)

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.c file);

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.c in 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]>

Bugs

This program is still beta. Testers wanted. Known bugs are:

Poor doublequotation.

All identifiers such as table and column names should be enclosed in double quotes. Program can't handle upper-case identifiers, like DBA. Lower-case identifiers are OK.

SET type emulation is not full. LIKE operation on

SETs, raw integer input values should be implemented

Makefile generated during output is platform-dependent and surely works only on Linux/gcc (FreeBSD/gcc probably works as well - not tested)
Generated libtypes.c contain line
        #include <postgres.h>

This file may be located not in standard compiler include path, you need to check it before compiling.

Authors

(c) 2000 Maxim V. Rudensky ([email protected]) (c) 2000 Valentine V. Danilchuk ([email protected])

License

BSD

From postgresql-contrib 7.4.7-6sarge6 in Debian 3.1 (Sarge). Parsed by carta from the page's man source.