Reference

my2pg.pl(1)

MySQL -> PostgreSQL dump conversion utility.

NAME

my2pg - MySQL -> PostgreSQL dump conversion utility.

SYNTAX

        mysqldump db ⎪ ./my2pg.pl [-n] > pgsqldump.sql
        vi libtypes.c
        make
        psql database < pgsqldump.txt
where

pgsqldump.sql

- file suitable for loading into PostgreSQL.

libtypes.c

- C source for emulated MySQL types (ENUM, SET) generated by my2pg

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.

COMMAND-LINE 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.

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])

CREDITS

Jeff Waugh <[email protected]> Joakim Lemström <[email protected]> ⎪⎪ <[email protected]> Yunliang Yu <[email protected]> Brad Hilton <[email protected]>

LICENSE

BSD